#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pk pop_back

using namespace std;

ll mod = 1e9 + 7;

ll kol = 0;
vector <ll> a;
vector <ll> ans;

void f(ll l, ll r, ll d)
{
    if(l == r)
        {ans[l] = d;return;}
    ll mx = 0, q = 0;
    for(ll i = l; i <= r; ++i)
    {
        if(mx < a[i])
        {
            mx = a[i];
            q = i;
        }
    }
    ans[q] = d;
    if(q != l)
        f(l, q - 1, d + 1);
    if(q != r)
        f(q + 1, r, d + 1);
}

void solve()
{
    ll n = 0, m = 0, k = 0, sum = 0;
    string s;
    cin >> n;
    a.resize(n + 1);
    ans.resize(n + 1);
    for(ll i = 1; i <= n; ++i)
        cin >> a[i];
    f(1, n, 0);
    for(ll i = 1; i <= n; ++i)
        cout << ans[i] << " ";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
//    freopen("input.in", "r", stdin);
//    freopen("output.out", "w", stdout);
    ll qwe = 1;
    cin >> qwe;
    while(qwe--)
    {
        solve();
        cout << "\n";
    }
}

