// By 0x0F #include<bits/stdc++.h> usingnamespace std; //#define int long long inlineintread(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();} while (ch >= '0' && ch <= '9') {x = x * 10 + ch - 48; ch = getchar();} return x * f; } int deg[1010], col[1010], tot; voidsolve(){ int n = read(); for (int i = 1; i <= n; i++) deg[i] = read(); while (1) { int maxd = 0, ind = 0; for (int i = 1; i <= n; i++) if (deg[i] >= maxd && !col[i]) maxd = deg[i], ind = i; if (ind == 0) { printf("! "); for (int i = 1; i <= n; i++) printf("%d ", col[i]); printf("\n"); fflush(stdout); for (int i = 1; i <= n; i++) col[i] = 0; tot = 0; break; } vector<int> vec; int cl = 0; vec.push_back(ind); for (int i = 1; i <= deg[ind]; i++) { printf("? %d\n", ind); fflush(stdout); int j = read(); vec.push_back(j); if (col[j] && !cl) {cl = col[j]; break;} } if (!cl) cl = ++tot; for (int i:vec) col[i] = cl; } } intmain(){ int t = read(); while (t--) solve(); return0; }