#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef pair PIII; #define gcd(x, y) __gcd(x, y) #define gcd3(x, y, z) __gcd(__gcd(x, y), z) const double EPS = 1e-8; const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const int MAXN = 100000 + 10; const int MOD = 1e9 + 7; int a[MAXN]; int dp[MAXN]; int b[MAXN]; int main() { int T; cin >> T; while (T--) { int n; cin >> n; int x; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } int len = 1; dp[1] = a[0]; b[0] = 1; for (int i = 1; i < n; ++i) { if (a[i] > dp[len]) { dp[++len] = a[i]; b[i] = len; } else { int p = lower_bound(dp + 1, dp + 1 + len, a[i]) - dp; dp[p] = a[i]; //cout << p << endl; b[i] = p; } } for (int i = 0; i < n; ++i) { printf("%d%c", b[i], i == n - 1 ? '\n' : ' '); } } return 0; }