5
5 3
2 4
3 1
4 5
 4
2 4
3 2
2 1
 5
5 3
2 4
3 1
4 5
 2
1 2
 4
3 4
2 3
3 1
 10
8 10
2 9
7 8
4 1
7 3
4 7
2 5
2 4
4 6
 5
3 4
3 2
3 1
1 5
 3
1 2
2 3
 5
1 2
1 3
1 4
1 5

1 2
2 3
2 4
 1 3
2 4
3 5
4 5
 1 2
 1 3
2 3
3 4
 1 4
2 4
2 5
2 9
3 7
4 6
4 7
7 8
8 10
 1 3
1 5
2 3
3 4
 1 2
2 3
 1 2
1 3
1 4
1 5

#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x= 0;
	char c= getchar();
	while(!isdigit(c)) c= getchar();
	while(isdigit(c)) x= x * 10 + (c & 15), c= getchar();
}
#define N 2001
int n, dep[N], a[N], f[N][2], t[N], fa[N], ma;
bool pre[N][2];
vector<int> k, d[N];
signed main() {
	read(n);
	printf("? 1\n"), fflush(stdout);
	for(int i= 1; i <= n; i++) read(dep[i]), ma= max(ma, dep[i]), ++a[dep[i]], d[dep[i]].push_back(i);
	for(int i= 1; i <= n; i++)
		if(dep[i] == 1) fa[i]= 1;
	for(int i= 1; i <= ma; i++) {
		f[i][0]= f[i - 1][1];
		pre[i][0]= 1;
		f[i][1]= min(f[i - 1][0], f[i - 1][1]) + a[i];
		pre[i][1]= (f[i - 1][1] < f[i - 1][0]);
	}
	int x= (f[ma][1] < f[ma - 1][1]) ? (ma) : (ma - 1);
	bool y= 1;
	for(int i= x; i; i--) {
		if(y == 1) k.push_back(i);
		y= pre[i][y];
	}
	for(auto &x : k) {
		for(auto &i : d[x]) {
			printf("? %d\n", i), fflush(stdout);
			for(int j= 1; j <= n; j++) {
				read(t[j]);
				if(t[j] == 1) {
					if(dep[j] == dep[i] - 1)
						fa[i]= j;
					else
						fa[j]= i;
				}
			}
		}
	}
	printf("!\n");
	for(int i= 2; i <= n; i++) printf("%d %d\n", i, fa[i]);
	fflush(stdout);
	return 0;
}