#include<bits/stdc++.h>
using namespace std;
int arr[100005];
int BIT[1000005];
void update(int ind,int val)
{
while(ind<=1000002)
{
BIT[ind]+=val;
ind+=(ind&(-ind));
}
}
int query(int ind)
{
int s=0;
while(ind>0)
{
s+=BIT[ind];
ind-=(ind&(-ind));
}
return s;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(BIT,0,sizeof(BIT));
int i,j;
int n;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&arr[i]);
long long answ=0;
for(i=n;i>=1;i--)
{
answ+=query(arr[i]-1);
update(arr[i],1);
}
for(i=1;i<=n;i++)
{
answ=answ-query(arr[i]-1)+query(1000002)-query(arr[i]);
printf("%lld ",answ);
}
printf("\n");
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFyclsxMDAwMDVdOwppbnQgQklUWzEwMDAwMDVdOwp2b2lkIHVwZGF0ZShpbnQgaW5kLGludCB2YWwpCnsKCXdoaWxlKGluZDw9MTAwMDAwMikKCXsKCQlCSVRbaW5kXSs9dmFsOwoJCWluZCs9KGluZCYoLWluZCkpOwoJfQp9CmludCBxdWVyeShpbnQgaW5kKQp7CglpbnQgcz0wOwoJd2hpbGUoaW5kPjApCgl7CgkJcys9QklUW2luZF07CgkJaW5kLT0oaW5kJigtaW5kKSk7Cgl9CglyZXR1cm4gczsKfQppbnQgbWFpbigpCnsKCWludCB0OwoJc2NhbmYoIiVkIiwmdCk7Cgl3aGlsZSh0LS0pCgl7CgkJbWVtc2V0KEJJVCwwLHNpemVvZihCSVQpKTsKCQlpbnQgaSxqOwoJCWludCBuOwoJCXNjYW5mKCIlZCIsJm4pOwoJCWZvcihpPTE7aTw9bjtpKyspCgkJc2NhbmYoIiVkIiwmYXJyW2ldKTsKCQlsb25nIGxvbmcgYW5zdz0wOwoJCWZvcihpPW47aT49MTtpLS0pCgkJewoJCQlhbnN3Kz1xdWVyeShhcnJbaV0tMSk7CgkJCXVwZGF0ZShhcnJbaV0sMSk7CgkJfQoJCWZvcihpPTE7aTw9bjtpKyspCgkJewoJCQlhbnN3PWFuc3ctcXVlcnkoYXJyW2ldLTEpK3F1ZXJ5KDEwMDAwMDIpLXF1ZXJ5KGFycltpXSk7CgkJCXByaW50ZigiJWxsZCAiLGFuc3cpOwoJCX0KCQlwcmludGYoIlxuIik7Cgl9Cn0=