#include #include #include #include using namespace std; const int maxn = 100000 + 5; int bit[maxn], a[maxn], b[maxn], c[maxn], n, m; void init() { memset(bit, 0, sizeof(bit)); } void update(int i, int v) { while(i <= m) { bit[i] = max(bit[i], v); i += i & -i; } } int query(int i) { int ret = 0; while(i) { ret = max(ret, bit[i]); i -= i & -i; } return ret; } int main() { int T; scanf("%d", &T); while(T--) { init(); int n; scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", a + i); c[i] = a[i]; } sort(c + 1, c + n + 1); m = unique(c + 1, c + n + 1) - c - 1; for(int i = 1; i <= n; ++i) { int k = lower_bound(c + 1, c + m + 1, a[i]) - c; b[i] = query(k - 1) + 1; update(k, b[i]); } for(int i = 1; i <= n; ++i) printf("%d%c", b[i], " \n"[i == n]); } return 0; }