#include <bits/stdc++.h>
using namespace std;
#define TC 1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void init() {
    ;
}

struct Node {
    int val;
    Node *left, *right;
    Node(int x) : val(x), left(NULL), right(NULL) {
    }
};

Node* build(vector<int>& v, int l, int r) {
    if (l > r) return NULL;
    if (l == r) {
        return new Node(v[l]);
    }
    
    int max_index = l, max_value = v[l];
    for (int i=l+1; i<=r; i++) {
        if (v[i] > max_value) {
            max_value = v[i];
            max_index = i;
        }
    }
    
    Node* root = new Node(max_value);
    root->left = build(v, l, max_index-1);
    root->right = build(v, max_index+1, r);
    return root;
}

void populateDepth(Node* root, vector<int>& res, int d=0) {
    if (!root)
        return;
        
    res[root->val] = d;
    populateDepth(root->left, res, d+1);
    populateDepth(root->right, res, d+1);
}


void solve() {
    int n; cin >> n;
    vector <int> v(n);
    
    for (auto &it : v)
        cin >> it;
        
    Node* root = build(v, 0, n-1);
    vector<int> depth(n+1);
    
    populateDepth(root, depth);
    for (int i=0; i<n; i++)
        cout << depth[v[i]] <<" ";
    cout << "\n";
}

int main() {
    IOS
    init();
    int t = 1;
    if (TC)
        cin >> t;

    while (t--) {
        solve();
    }
}
