#include <bits/stdc++.h>
#include "library.h"
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9;
int n;
vector <int> a[mn], res;
vector <int> merge(vector <int> x, vector <int> y){
vector <int> ans(n);
ans[x.front()] = 1, ans[y.front()] = 1;
if(Query(ans) == 1){
reverse(all(y));
for(auto i : x) y.push_back(i);
return y;
}
ans[x.front()] = 0, ans[y.front()] = 0;
ans[x.front()] = 1, ans[y.back()] = 1;
if(Query(ans) == 1){
for(auto i : x) y.push_back(i);
return y;
}
ans[x.front()] = 0, ans[y.back()] = 0;
ans[x.back()] = 1, ans[y.front()] = 1;
if(Query(ans) == 1){
for(auto i : y) x.push_back(i);
return x;
}
ans[x.back()] = 0, ans[y.front()] = 0;
reverse(all(y));
for(auto i : y) x.push_back(i);
return x;
}
void Solve(int N) {
n = N;
for(int i = 0; i < n; i++) a[i].push_back(i);
for(int st = 0; st < n - 1; st ++){
int l = st + 1, r = n - 1, ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
vector <int> ask(n);
for(int i = st; i <= mid; i++){
for(auto j : a[i]) ask[j] = 1;
}
if(Query(ask) <= mid - st){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
a[ans] = merge(a[st], a[ans]);
debug(ans, a[ans]);
}
for(auto &i : a[n - 1]) i ++;
Answer(a[n - 1]);
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro