#include <bits/stdc++.h>
using namespace std;

void solve(unordered_map<int, int> index, int arr[], int v[], int l, int r, int height){
    if(l > r){
        return;
    }
    int max_ele=INT_MIN;
    for(int i=l; i<=r; i++){
        max_ele = max(arr[i], max_ele);
    }
    v[index[max_ele]] = ++height;
    solve(index, arr, v, l, index[max_ele]-1, height);
    solve(index, arr, v, index[max_ele]+1, r, height);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int arr[n];
        int v[n];
        unordered_map<int, int> index;
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
            index[arr[i]] = i;
        }
        int height = 0;
        v[index[n]] = height;
        solve(index, arr, v, 0, index[n]-1, height);
        solve(index, arr, v, index[n]+1, n-1, height);
        for(int i=0; i<n; i++){
            cout<<v[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}