#include<bits/stdc++.h>
using namespace std;
struct st{
int val,num;
}a[100005];
int na[100005];
bool cmp(struct st a,struct st b)
{
return a.val<=b.val;
}
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i].val,a[i].num=i;
sort(a+1,a+n+1,cmp);//排序
for(int i=1;i<=n;i++)//归位
{
int now=a[i].num,pre=a[i-1].num;
if(i==1)na[now]=1;
else
{
if(a[i].val==a[i-1].val)na[now]=na[pre];//去重
else na[now]=na[pre]+1;
}
}
for(int i=1;i<=n;i++)
cout<<na[i]<<' ';
cout<<endl;
}
return 0;
}