Problem: Very soon, the new cell phone services provider "BerLine" will begin its work in Berland!

The start of customer service is planned along the main street of the capital. There are n base stations that are already installed. They are located one after another along the main street in the order from the 1-st to the n-th from left to right. 

Currently, all these base stations are turned off. They will be turned on one by one, one base station per day, according to some permutation p = [p_1, p_2, ..., p_n] ( 1 ≤ p_i ≤ n), where p_i is the index of a base station that will be turned on on the i-th day. Thus, it will take n days to turn on all base stations.

Each base station is characterized by its operating frequency f_i — an integer between 1 and 24, inclusive.

There is an important requirement for operating frequencies of base stations. Consider an arbitrary moment in time. For any phone owner, if we consider all base stations turned on in the access area of their phone, then in this set of base stations there should be at least one whose operating frequency is unique among the frequencies of these stations. Since the power of the phone and the position are not known in advance, this means that for any nonempty subsegment of turned on base stations, at least one of them has to have the operating frequency that is unique among the stations of this subsegment.

For example, let's take a look at a case of n = 7, all n stations are turned on, and their frequencies are equal to f = [1, 2, 1, 3, 1, 2, 1]. Consider any subsegment of the base stations — there is a base station with a unique frequency within this subsegment. However, if f = [1, 2, 1, 2, 3, 2, 1], then there is no unique frequency on the segment [1, 2, 1, 2] from the index 1 to the index 4, inclusive.

Your task is to assign a frequency from 1 to 24 to each of n base stations in such a way that the frequency requirement is met at every moment. Remember that the base stations are turned on in the order of the given permutation p.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 50) — the number of test cases in the input. Then t test case descriptions follow.

The first line of a test case contains an integer n ( 1 ≤ n ≤ 8 500) — the number of "BerLine" base stations.

The following line contains n distinct integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) — the order in which the base stations are turned on, i. e. on the i-th day the base station with the index p_i is turned on.

It is guaranteed that a correct answer exists for all test cases in the input.

Output

Print exactly t lines, where the j-th line contains the answer for the j-th test case in the input. Print the required frequencies f_1, f_2, ..., f_n (1 ≤ f_i ≤ 24). If there are several possible answers, print any of them.

Example

Input


5
3
1 3 2
3
1 2 3
1
1
10
6 10 4 2 7 9 5 8 3 1
10
2 4 6 9 1 8 10 5 3 7


Output


1 3 2 
10 20 10
1 
2 3 4 5 3 1 3 5 4 2 
1 2 3 4 5 6 7 8 9 10

Note

In the first test case n = 3 and p = [1, 3, 2]. The base stations can be assigned frequencies [1, 3, 2].

  * Day 1: only the base station 1 is turned on, its frequency is 1. 
  * Day 2: the base stations 1 and 3 are turned on, their frequencies are [1, 2]. 
  * Day 3: all base stations are turned on, their frequencies are [1, 3, 2] (in the direction along the street). 



On each day, each nonempty subsegment of turned on base stations has a base station with a unique frequency among this subsegment. It can be shown that three distinct frequencies are necessary in this test case.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n;
int p[8505];
int wh[8505];
int ans[8505];
int level[8505];
int nxt[9][8505];
int prv[9][8505];
pair<int, int> bros[9][8505];
int svd = 0, lsz, l;
inline void go(int &f) {
  int id = f, t = 0;
  f = nxt[l][f];
  if (wh[f] < wh[id]) id = f, t = 1;
  f = nxt[l][f];
  if (wh[f] < wh[id]) id = f, t = 2;
  f = nxt[l][f];
  if (t == 2) bros[l - 1][id] = {prv[l][prv[l][id]], prv[l][id]};
  if (t == 1) bros[l - 1][id] = {prv[l][id], nxt[l][id]};
  if (t == 0) bros[l - 1][id] = {nxt[l][id], nxt[l][nxt[l][id]]};
  level[id]--, lsz++, nxt[l - 1][svd] = id, nxt[l - 1][id] = n + 1,
                              prv[l - 1][id] = svd;
  svd = id;
}
bool comp(int a, int b) { return wh[a] < wh[b]; }
struct genQ {
  vector<int> pos;
  int l, r;
};
vector<genQ> s10;
void solve(vector<int> pos, int l, int r) { s10.push_back({pos, l, r}); }
void solve1() {
  vector<int> pos = s10.back().pos;
  int l = s10.back().l;
  int r = s10.back().r;
  s10.pop_back();
  int t = 0;
  for (int i = 0; i < pos.size(); i++) {
    if (ans[pos[i]] == 0) t = 1;
  }
  if (!t) return;
  if (pos.size() < 4) {
    set<int> allowed;
    for (int i = l; i < l + pos.size(); i++) allowed.insert(i);
    for (int i = 0; i < pos.size(); i++)
      if (ans[pos[i]] != 0) allowed.erase(ans[pos[i]]);
    for (int i = 0; i < pos.size(); i++) {
      if (ans[pos[i]] == 0) {
        ans[pos[i]] = *allowed.begin();
        allowed.erase(allowed.begin());
      }
    }
    return;
  }
  if (pos.size() == 4) {
    int t = 0;
    sort((pos).begin(), (pos).end(), comp);
    for (int lc = l; lc <= l + 2; lc++) {
      vector<int> perm = {l, l + 1, l + 2};
      sort((perm).begin(), (perm).end());
      while (1) {
        int ok = 1;
        for (int i = 0; i < 3; i++) {
          if (ans[pos[i]] != 0 && ans[pos[i]] != perm[i]) {
            ok = 0;
            break;
          }
        }
        if (ans[pos[3]] != 0 && ans[pos[3]] != lc) ok = 0;
        int targ = 0;
        for (int i = 0; i < 3; i++) {
          if (perm[i] == lc) targ = i;
        }
        for (int i = 0; i < 3; i++) {
          if (pos[i] > pos[targ] && pos[i] < pos[3]) {
            targ = -1;
            break;
          }
          if (pos[i] < pos[targ] && pos[i] > pos[3]) {
            targ = -1;
            break;
          }
        }
        if (targ == -1 && ok) {
          for (int i = 0; i < 3; i++) ans[pos[i]] = perm[i];
          ans[pos[3]] = lc;
          t = 1;
          break;
        }
        if (!next_permutation(perm.begin(), perm.end())) break;
      }
      if (t) break;
    }
    return;
  }
}
void solve2(vector<int> pos, int l, int r) {
  s10.push_back({pos, l, r});
  solve1();
}
void solve(int i, int gl) {
  vector<int> bb;
  bb.push_back(bros[gl][prv[gl][p[i]]].first);
  bb.push_back(bros[gl][prv[gl][p[i]]].second);
  bb.push_back(bros[gl][p[i]].first);
  bb.push_back(bros[gl][p[i]].second);
  bb.push_back(bros[gl][nxt[gl][p[i]]].first);
  bb.push_back(bros[gl][nxt[gl][p[i]]].second);
  vector<int> p1, p2;
  for (int j = 0; j < bb.size(); j++)
    if (prv[gl][p[i]] <= bb[j] && bb[j] <= nxt[gl][p[i]])
      if (bb[j] < p[i])
        p1.push_back(bb[j]);
      else
        p2.push_back(bb[j]);
  if (nxt[gl][p[i]] != n + 1 && prv[gl][p[i]] != 0) {
    vector<int> bc;
    if (prv[gl][p[i]] <= bros[gl][prv[gl][p[i]]].first &&
        bros[gl][prv[gl][p[i]]].first <= nxt[gl][p[i]])
      bc.push_back(bros[gl][prv[gl][p[i]]].first);
    if (prv[gl][p[i]] <= bros[gl][prv[gl][p[i]]].second &&
        bros[gl][prv[gl][p[i]]].second <= nxt[gl][p[i]])
      bc.push_back(bros[gl][prv[gl][p[i]]].second);
    if (prv[gl][p[i]] <= bros[gl][nxt[gl][p[i]]].first &&
        bros[gl][nxt[gl][p[i]]].first <= nxt[gl][p[i]])
      bc.push_back(bros[gl][nxt[gl][p[i]]].first);
    if (prv[gl][p[i]] <= bros[gl][nxt[gl][p[i]]].second &&
        bros[gl][nxt[gl][p[i]]].second <= nxt[gl][p[i]])
      bc.push_back(bros[gl][nxt[gl][p[i]]].second);
    solve(bc, gl * 3 + 1, gl * 3 + 3);
  }
  int LL = prv[gl][p[i]], RR = nxt[gl][p[i]];
  if (LL != 0) solve(p1, gl * 3 + 1, gl * 3 + 3);
  if (RR != n + 1) solve(p2, gl * 3 + 1, gl * 3 + 3);
  if (LL == 0) {
    vector<int> bc;
    for (int j = 0; j < bb.size(); j++)
      if (1 <= bb[j] && bb[j] < p[i]) bc.push_back(bb[j]);
    solve(bc, gl * 3 + 1, gl * 3 + 3);
  }
  if (RR == n + 1) {
    vector<int> bc;
    for (int j = 0; j < bb.size(); j++)
      if (p[i] < bb[j] && bb[j] <= n) bc.push_back(bb[j]);
    solve(bc, gl * 3 + 1, gl * 3 + 3);
  }
  prv[gl][RR] = LL;
  nxt[gl][LL] = RR;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++)
    wh[p[i]] = i, ans[i] = 0, nxt[8][i] = i + 1, level[i] = 8,
    prv[8][i] = i - 1;
  for (int i = 1; i <= 8; i++) nxt[i][0] = 1, nxt[i][n + 1] = n + 1;
  wh[n + 1] = n + 1;
  if (n > 4)
    for (l = 8; l >= 1; l--) {
      int f = nxt[l][0];
      lsz = 0, svd = 0;
      while (f != n + 1) go(f);
      if (lsz <= 4) break;
    }
  vector<int> calls[8];
  for (int i = n; i >= 1; i--) {
    for (int gl = level[p[i]]; gl < 8; gl++) {
      calls[gl].push_back(i);
    }
  }
  for (int gl = 1; gl != 8; gl++) {
    for (auto i : calls[gl]) solve(i, gl);
    while (s10.size()) solve1();
  }
  for (int lvl = 1; lvl <= 8; lvl++) {
    vector<int> ao;
    for (int i = 1; i <= n; i++)
      if (lvl == level[i] && ans[i] == 0) ao.push_back(i);
    solve2(ao, lvl * 3 - 2, lvl * 3);
  }
  for (int i = 1; i <= n; i++) cout << 25 - ans[i] << " ";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}