#include <bits/stdc++.h>
using namespace std;
const int N1 = 8503;
int T, n;
int flag[N1], col[N1];
vector<int> nearby[N1];
void solve() {
  scanf("%d", &n);
  vector<int> a(n), b;
  for (int i = 0; i < n; i++) {
    scanf("%d", a.data() + i);
  }
  for (int i = 1; i <= n; i++) {
    flag[i] = 0;
  }
  int dep = 1;
  while (a.size()) {
    set<int> S;
    for (auto x : a) flag[x] = 0;
    int idx = 0;
    for (auto x : a) {
      set<int>::iterator it = S.lower_bound(x);
      nearby[idx].clear();
      if (it != S.end()) nearby[idx].push_back(*it);
      if (it != S.begin()) nearby[idx].push_back(*--it);
      S.insert(x);
      idx++;
    }
    for (int i = (signed)a.size() - 1; ~i; i--) {
      int x = a[i];
      if (!flag[x]) {
        for (auto y : nearby[i]) flag[y] = 2;
        flag[x] = 1;
        col[x] = dep;
      }
    }
    b.clear();
    for (auto x : a)
      if (flag[x] ^ 1) b.push_back(x);
    a = b;
    dep++;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", col[i]);
  }
  putchar('\n');
}
int main() {
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
