#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>

using namespace std;
const int MAX = 102;
int answer[MAX];
int a[MAX];

void solution(int left, int right, int level) {
    int maxV = 0;
    int index = -1;
    for (int i = left; i <= right; ++i) {
        if (maxV < a[i]) {
            maxV = a[i];
            index = i;
        }
    }

    if (answer[index] == -1) {
        answer[index] = level;
        solution(left, index - 1, level + 1);
        solution(index + 1, right, level + 1);    
    }
}

int main() {
    //freopen("D.in", "rt", stdin);
    std::ios::sync_with_stdio(false);
    
    int T;
    cin >> T;
    
    for (int t = 0; t < T; ++t) {
        memset(answer, -1, sizeof(answer));
        memset(a, 0, sizeof(a));

        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        
        solution(0, n - 1, 0);
        
        for (int i = 0; i < n; ++i) {
            cout << answer[i];
            if (i != n - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}
