#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int N = 100010; int tree[N], bn, a[N], b[N]; inline int f (int x) { return x & -x; } void add (int x, int y) { for (int i = x; i <= bn; i += f(i)) tree[i] = max (tree[i], y); } int qry (int x) { int r = 0; for (int i = x; i; i -= f (i)) r = max (r, tree[i]); return r; } int main () { // freopen ("in.txt", "r", stdin); int T, n, m; cin >> T; while (T--) { scanf ("%d", &n); for (int i = 1; i <= n; i++) { scanf ("%d", &a[i]); b[i] = a[i]; } sort (b + 1, b + 1 + n); bn = unique (b + 1, b + 1 + n) - b - 1; memset (tree, 0, sizeof (int) * (bn + 5)); for (int i = 1; i <= n; i++) { a[i] = lower_bound (b + 1, b + 1 + bn, a[i]) - b; // cout << a[i] << endl; int tmp = qry (a[i] - 1) + 1; printf ("%d", tmp); if (i == n) printf ("\n"); else printf (" "); add (a[i], tmp); } } }