#include <bits/stdc++.h>
const int max_N = 8507;
int n, ans[max_N];
std::vector<int> P;
bool flag[max_N];
int read_int() {
  char c = getchar();
  int ans = 0;
  bool neg = false;
  while (!isdigit(c)) neg |= (c == '-'), c = getchar();
  while (isdigit(c)) ans = 10 * ans + c - '0', c = getchar();
  return neg ? -ans : ans;
}
void write_int(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write_int(x / 10);
  putchar(x % 10 + '0');
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
void _min(int &x, int y) {
  if (x > y) x = y;
}
void _max(int &x, int y) {
  if (x < y) x = y;
}
void solve() {
  std::fill(ans, ans + P.size(), 0);
  for (int w = 1; !P.empty(); w++) {
    std::vector<int> nxt;
    std::set<int> _set = {P.begin(), P.end()};
    std::set<int>::iterator it;
    for (int i = P.size() - 1; i >= 0; i--) {
      it = _set.find(P[i]);
      if (!flag[P[i]]) {
        ans[P[i]] = w;
        if (it != _set.begin()) flag[*std::prev(it)] = true;
        if (std::next(it) != _set.end()) flag[*std::next(it)] = true;
      }
      _set.erase(it);
    }
    for (int i = 0; i < P.size(); i++)
      if (flag[P[i]]) flag[P[i]] = false, nxt.push_back(P[i]);
    P.swap(nxt);
  }
}
int main() {
  int t = read_int();
  while (t--) {
    P.resize(n = read_int());
    for (int i = 0; i < n; i++) P[i] = read_int() - 1;
    solve();
    for (int i = 0; i < n; i++)
      write_int(ans[i]), putchar(i + 1 == n ? '\n' : ' ');
  }
  return 0;
}
