#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int maxn = 105;
int n, p[maxn], q[maxn], mnp[maxn], mxp[maxn];
bool ima[maxn];
vii ost;
int qu(){
cout << "query ";
for (int i = 1; i <= n; i++) cout << q[i] << " ";
cout << endl;
int res;
cin >> res;
return res;
}
void minnaj(){
bool mnj = 0;
for (int i = 1; i <= n; i++){
if (q[i] == mnp[i]) continue;
if (q[i] < mnp[i]) mnj = 1;
break;
}
if (mnj)
for (int i = 1; i <= n; i++)
mnp[i] = q[i];
}
void maxxaj(){
bool vc = 0;
for (int i = 1; i <= n; i++){
if (q[i] == mxp[i]) continue;
if (q[i] > mxp[i]) vc = 1;
break;
}
if (vc)
for (int i = 1; i <= n; i++)
mxp[i] = q[i];
}
void rek(int tr){
if (tr == n + 1){
if (qu()){
minnaj();
maxxaj();
}
return;
}
for (int i = 1; i <= n; i++){
if (ima[i]) continue;
ima[i] = 1;
q[tr] = i;
rek(tr + 1);
ima[i] = 0;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
for (int i = 1; i <= n; i++)
mnp[i] = n + 1;
rek(1);
cout << "end\n";
for (int i = 1; i <= n; i++)
cout << mnp[i] << " ";
cout << "\n";
for (int i = 1; i <= n; i++)
cout << mxp[i] << " ";
cout << endl;
return 0;
}