#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=110;
int deep[N];
int num[N];
void dfs(int l,int r,int now,int dp)//1,5,2,0
{
	if(l==r) return ;
	if(l<now)
	{
		int tar=now-1;
		for(int i=l;i<now-1;i++)
		{
			if(num[i]>num[tar]) tar=i;
		}
		deep[tar]=dp+1;
		dfs(l,now-1 ,tar , dp+1);
	}
	if(r>now)
	{
		int tar=now+1;
		for(int i=now+2;i<=r;i++)
		{
			if(num[i]>num[tar])  tar=i;
		}
		deep[tar]=dp+1;
		dfs(now+1,r,tar,dp+1);
	}
}
int main()
{
	IOS
	int t;	cin>>t;
	while(t--)
	{
	int n;	cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>num[i];
		}
		memset(deep,0,sizeof(deep));
		int tar=1;
		for(int i=2;i<=n;i++) 
		{
			if(num[i]>num[tar]) tar=i;
		}
		deep[tar]=0;
		dfs(1,n,tar,0);
		for(int i=1;i<=n;i++) cout<<deep[i]<<" ";
		cout<<endl;//2222
	}
	return 0;
}