#include <bits/stdc++.h>

using namespace std;

vector<int> values;
vector<int> assigned_depths;

void calculate_depths(int start_idx, int end_idx, int current_depth) {
    if (start_idx > end_idx) {
        return;
    }

    int max_val_idx = start_idx;
    for (int i = start_idx + 1; i <= end_idx; ++i) {
        if (values[i] > values[max_val_idx]) {
            max_val_idx = i;
        }
    }

    assigned_depths[max_val_idx] = current_depth;

    calculate_depths(start_idx, max_val_idx - 1, current_depth + 1);
    calculate_depths(max_val_idx + 1, end_idx, current_depth + 1);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int test_cases;
    cin >> test_cases;
    while (test_cases--) {
        int array_size;
        cin >> array_size;

        values.assign(array_size, 0);
        assigned_depths.assign(array_size, 0);

        for (int i = 0; i < array_size; ++i) {
            cin >> values[i];
        }

        calculate_depths(0, array_size - 1, 0);

        for (int i = 0; i < array_size; ++i) {
            cout << assigned_depths[i] << (i == array_size - 1 ? "" : " ");
        }
        cout << endl;
    }

    return 0;
}