#include<bits/stdc++.h>
#define f first
#define s second
#define _ ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

typedef long long ll;

const int MAX = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

pair<int,int> seg[2*110];
int n;
vector<int> v;
vector<int> dp;

void build(){
	for(int i = 0; i < n; i++) seg[n+i] = {v[i], i};
	for(int i = n-1; i >= 0; i--)
		seg[i] = seg[i*2].f >= seg[i*2+1].f ? seg[i*2] : seg[i*2+1]; 
}
pair<int,int> query(int a, int b){
	pair<int,int> ret = {-1, -1};
	for(a += n, b += n; a <= b; ++a /= 2, --b /= 2){
		if (a % 2 == 1) ret = (ret.f >= seg[a].f ? ret : seg[a]);
		if (b % 2 == 0) ret = (ret.f >= seg[b].f ? ret : seg[b]);
	}
	return ret;
}

void get_dp(int l, int r, int dpt=0){
	if(l > r) return;
	pair<int,int> mx = query(l, r);

	dp[mx.s] = dpt;
	get_dp(mx.s+1, r, dpt+1);
	get_dp(l, mx.s-1, dpt+1);
}

void solve(){

	cin >> n;
	v = vector<int>(n);
	dp = vector<int>(n);
	
	for(int &x: v)
		cin >> x;
	build();

	get_dp(0, n-1);
	for(int i = 0; i < n; i++){
		if(i) cout << " " ;
		cout << dp[i];
	}
	cout << endl;

}

int main(){_
	int t = 1;
	cin >> t;	
	while(t--)
		solve();
}
