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;
#define ll				long long int
#define f(n) 			for(int i=0;i<n;i++)
#define fo(n)			for(int j=0;j<n;j++)
#define ff 				first
#define ss 				second
#define pb 				push_back
#define pii 			pair<int,int>
#define vi 				vector<int>
#define vp 				vector<pii>
#define test            int tt; cin>>tt; while(tt--)
#define mod 			1000000007
#define all(v)			v.begin(),v.end()

int main()
{
	ll n;
	cin >> n;
	set<pair<ll, ll>>v;
	vector<ll>dis[n + 1];
	bool called[n+1]={};
	cout << "? " << 1 << endl;
	f(n) {
		ll x;
		cin >> x;
		dis[x].pb(i + 1);
	}
	for (auto x : dis[1]) {
		v.insert({1, x});
	}
	for (ll d = 2; d <= n; d++) {
		if(dis[d].size()==0)break;
		if (dis[d - 1].size() == 1) {
			for (auto x : dis[d]) {
				ll y = dis[d - 1][0];
				ll z = x;
				if (y > z)swap(y, z);
				v.insert({y, z});
			}
			continue;
		}
		if (dis[d - 1].size() + dis[d + 1].size() >= dis[d].size()) {
			called[d]=true;
			for (auto x : dis[d]) {
				cout << "? " << x << endl;
				ll a[n];
				f(n) {
					cin >> a[i];
					if (a[i] == 1) {
						ll y = i + 1;
						ll z = x;
						if (y > z)swap(y, z);
						v.insert({y, z});
					}
				}
			}
		}
		else {
			if(called[d-1]){
				continue;
			}
			for (auto x : dis[d-1]) {
				cout << "? " << x << endl;
				ll a[n];
				f(n) {
					cin >> a[i];
					if (a[i] == 1) {
						ll y = i + 1;
						ll z = x;
						if (y > z)swap(y, z);
						v.insert({y, z});
					}
				}
			}
		}

	}
	cout << "!" << endl;
	for (auto x : v) {
		cout << x.ff << " " << x.ss << endl;
	}
}



