#include<bits/stdc++.h>
using namespace std;
#define int int64_t
vector<int> A, D;
void calcDepth(int left, int right, int depth) {
		int idx = max_element(A.begin()+left, A.begin()+right+1) - A.begin();
		D[idx] = depth;
		if (left <= idx-1) calcDepth(left, idx-1, depth+1);
		if (idx+1 <= right) calcDepth(idx+1, right, depth+1);
	return;
}
void solve() {
		int N; cin >> N;
		A.clear(); A.resize(N); for (auto &x : A) cin >> x;
		D.clear(); D.resize(N);
		calcDepth(0, N-1, 0);
		for (auto x : D) cout << x << " "; cout << endl;
	return;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
		int T; cin >> T; for (int t = 1; t <= T; ++t) solve();
	return 0;
}