#include #include #include #include #include #include #define LL long long using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e5 + 10; int a[N], dp[N], ans[N]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); fill(dp, dp + n + 1, inf); for (int i = 0; i < n; i++) { int pos = lower_bound(dp + 1, dp + 1 + n, a[i]) - dp; ans[i] = pos; dp[pos] = a[i]; } for (int i = 0; i < n; i++) printf("%d%c", ans[i], i != n - 1 ? ' ' : '\n'); } return 0; }