#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
ll int mod=1e9+7;//998244353;


ll int mul(ll int x, ll int y)
{
    return (x * 1ll * y) % mod;
}


ll int add(ll int x,ll int y)
{
    x += y;
    while(x >= mod) x -= mod;
    while(x < 0) x += mod;
    return x;
}


long long power(long long a, long long b,ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res%m;
    }
ll int n;
ll int a[105];
ll int d[105];
ll int fun(int i,int j,int l)
{
    if(i>j)
    return 0;
    if(i==j)
    {
        d[i]=l;
        return 0;
    }
    ll int ma=0;
    ll int o=0;
    for(int k=i;k<=j;k++)
    {
        ma=max(ma,a[k]);
        if(ma==a[k])
        o=k;
    }
    d[o]=l;
    return  fun(i,o-1,l+1)+fun(o+1,j,l+1);
}
 int main() {
    ios;
    ll int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        memset(d,0,sizeof(d));
        fun(0,n-1,0);
        for(int i=0;i<n;i++)
        cout<<d[i]<<" ";
        cout<<endl;
    }
}