#include <iostream>
#include <bits/stdc++.h>
#define inf 1000000007
#define ll long long
#define fr first
#define sc second
using namespace std;

//fast I/O 
auto optimizer = []() {  // makes I/O fast
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();

//power mode where (x^y) % p is calculated in log (y) time
int power(ll x, ll y, ll p)  
{  
    int res = 1;
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

//Code -
void func(vector<ll>& vect, vector<ll>& pos, ll s, ll e, ll depth){
    if(s > e || s > vect.size()-1 || e < 0){
        return;
    }
    ll index = s;
    ll prev = vect[s];
    for(ll i = s+1; i <= e; i++){
        if(vect[i] > prev){
            index = i;
            prev = vect[i];
        }
    }
    pos[index] = depth;
    func(vect,pos,s,index-1,depth+1);
    func(vect,pos,index+1,e,depth+1);
}

int main() {
	ll n,i,j,t,m,temp;
    cin >> t;
    for(i = 0; i < t; i++){
        cin >> n;
        vector<ll> vect;
        for(j = 0; j < n; j++){
            cin >> temp;
            vect.push_back(temp);
        }
        vector<ll> pos(n,0);
        func(vect,pos,0,n-1,0);
        for(j = 0; j < n; j++){
            cout << pos[j] << " ";
        }
        cout << endl;
    }
    return 0;
}