#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

typedef long long LL;

const int N = 110;

int T;
int n;
int a[N], res[N];

void dfs(int l, int r, int dep) {
    if (l > r || l < 1 || r > n) return;
    
    if (l == r) {
        res[l] = dep;
        return;
    }
    
    int pos, Max = -1;
    for (int i = l; i <= r; i ++)
        if (Max < a[i]) {
            Max = a[i];
            pos = i;
        }
    res[pos] = dep;

    dfs(l, pos - 1, dep + 1);
    dfs(pos + 1, r, dep + 1);
    
    return;
}

int main() {
    cin >> T;
    while (T --) {
        cin >> n;
        for (int i = 1; i <= n; i ++) cin >> a[i];
        
        dfs(1, n, 0);
        
        for (int i = 1; i <= n; i ++) cout << res[i] << " \n"[i == n];
    }
    
    return 0;
}