/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

int n;
vector<int> a;
vector<int> res;

void rec(int l, int r, int depth){
    if(l > r)
        return;
    if(l == r){
        res[l] = depth;
        return;
    }
    int idx = -1, maxi = -1;
    for(int i = l; i <= r; i++){
        if(maxi < a[i]){
            maxi = a[i];
            idx = i;
        }
    }
    assert(idx != -1);
    res[idx] = depth;
    rec(l, idx - 1, depth + 1);
    rec(idx + 1, r, depth + 1);
    return;
}

void solve(){
    cin >> n;
    a.clear();
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
        res.pb(0);
    }
    rec(0, n - 1, 0);
    for(int i = 0; i < n; i++){
        cout << res[i] << " ";
    }
    cout << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}