#include #include #include using namespace std; const int MAXN = 1e5+10; int ans[MAXN], t[MAXN]; int search(int num,int low, int high) { int mid; while(low <= high) { mid = low + high >> 1; if(num > t[mid]) low = mid+1; else high = mid - 1; } return low; } int main() { int k; scanf("%d", &k); while(k--) { int n; scanf("%d", &n); memset(ans, 0, sizeof(ans)); memset(t, 0, sizeof(t)); int m = 1; scanf("%d", &t[1]); ans[0] = 1; for(int i = 1; i < n; i++) { int x; scanf("%d", &x); if(x > t[m]) { m++; t[m] = x; ans[i] = m; } else { int p = search(x, 1, m); t[p] = x; ans[i] = p; } } printf("%d", ans[0]); for(int i = 1; i < n; i++) printf(" %d", ans[i]); printf("\n"); } return 0; }