#include<bits/stdc++.h>
using namespace std;

#define e "\n"
#define ll long long
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007

int ans[105],b;

void fun(vector<int>arr,int i,int n, int c)
{
    //cout << i << " " << n << " " << c << e;
    if(i >= n)
        return;
    if(i == n-1)
    {
        ans[i] = c;
        return;
    }
    int k,mx = arr[i];
    for(k=i+1;k<n;k++)
    {
        if(arr[k] > mx)
            mx = arr[k];
    }
    for(k=i;k<n;k++)
    {
        if(arr[k] == mx)
        {
            ans[k] = c;
            //cout << "k " << k << " " <<arr[k] << " " << ans[k] << e;
            break;
        }
    }
    fun(arr,k+1,n,c+1);
    fun(arr,i,k,c+1);
}

int main()
{
    int t;
    fio;
    t = 1;
    cin >> t;
    while(t--)
    {
        memset(ans,0,sizeof(ans));
        int n;
        cin >> n;
        int a,i;
        vector<int>arr;
        for(i=0;i<n;i++)
        {
            cin >> a;
            arr.push_back(a);
        }
        int c = 0;
        fun(arr,0,n,c);
        for(i=0;i<n;i++)
        {
            cout << ans[i] << " ";
        }
        cout << e;
    }
    return 0;
}
