#include <iostream>
#include <bits/stdc++.h>
#define Momen83 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define endll '\n'
#define sz(a) (int)(a).size()
#define File freopen("string.in.txt","r",stdin); freopen("string.out.txt","w",stdout);
#define fl(i,a,b) for(int i=a;i<b;i++)
const int Mod =1e9+7 , N=1e5+1;
using namespace std;
int a[101],n,dep[101];
int cal_max(int a[],int s,int e)
{
     int mx=0,mxi=0;
     for(int i=s;i<=e;i++)
     {
          if(mx<a[i]){mx=a[i];mxi=i;}
     }
     return mxi;
}
void solve(int s,int e,int d)
{
     if(s>e){return;}
     int index= cal_max(a,s,e);
     dep[index]=d;
     solve(s,index-1,d+1);
     solve(index+1,e,d+1);

}

int main()
{
     Momen83;
    int tc;cin>>tc;
    while(tc--)
    {
      memset(dep,-1,sizeof dep);
        cin>>n;
          for(int i=0;i<n;i++)
         {
              cin>>a[i];
         }

         solve(0,n-1,0);
          for(int i=0;i<n;i++)
         {
             cout<<dep[i]<<" ";
         }

    }
}
