#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector gen_permutation(int n) { random_device seed_gen; mt19937 engine(seed_gen()); vector ans(n); for (int i = 0; i < n; i++) ans[i] = i; shuffle(ans.begin(), ans.end(), engine); return ans; } class Simulator{ public: int n, n_asked; vector p; Simulator(int n): n(n), n_asked(0), p(gen_permutation(n)) {} vector ask(vector a){ n_asked++; assert(a.size() == n-1); vector b(n); b[0] = p[0]; for(int i = 0; i < n-1; i++){ if(a[i] == 0){ b[i+1] = min(b[i], p[i+1]); }else{ b[i+1] = max(b[i], p[i+1]); } } return b; } void verify(vector ans){ print_vector(p); print_vector(ans); for(int i = 0; i < n; i++){ assert(p[i] == ans[i]); } assert(n_asked <= 10); } }; // #define DEBUG void solve(){ int n; cin >> n; #ifdef DEBUG auto sim = Simulator(n); auto ask = [&](vector a){ return sim.ask(a); }; auto verify = [&](vector ans){ return sim.verify(ans); }; #else auto ask = [&](vector a){ cout << "? "; for(int x: a) cout << x << ' '; cout << endl; vector ans(n); for(int i = 0; i < n; i++){ cin >> ans[i]; ans[i]--; } return ans; }; auto verify = [&](vector ans){ cout << "! "; for(int x: ans) cout << x+1 << ' '; cout << endl; }; #endif vector ans(n); auto process = [&](vector a){ auto b = ask(a); ans[0] = b[0]; for(int i = 1; i < n; i++){ if(b[i] != b[i-1]) ans[i] = b[i]; } }; vector a(n-1); for(int i = 0; i < n-1; i++) a[i] = i%2; process(a); for(int i = 0; i < n-1; i++) a[i] = (i+1)%2; process(a); verify(ans); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }