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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset Operations: order_of_key(k) -> Number of elements strictly smaller than k, find_by_order(k) -> kth element in the set

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvb vector<vb>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair

const long double PI = 3.141592653589793238462643383279502884197169399;

template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res.push_back(static_cast<char>('0' + v[i]));
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifndef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int mod = 1e9 + 7;

int N;

vi query(int node){
	cout << "? " << node << endl;
	vi D(N+1);
	for(int i=1 ; i<=N ; ++i)cin >> D[i];
	
	return D;
}

void solve(){
	cin >> N;
	
	set<pii> edges;
	set<int> ent;
	
	int node = 1;
	vi D = query(1);
	for(int dist=1 ; ; ++dist){
		int cnt=0;
		int Tnode=-1;
		for(int i=1 ; i<=N ; ++i){
			if(D[i] == dist){
				pii P = {node, i}, rP = {i, node};
				++cnt;
				if(edges.find(P) == edges.end() && edges.find(rP) == edges.end()){
					edges.insert(P);
					Tnode = i;
					ent.insert(i);ent.insert(node);
				}
			}
		}
		if(cnt != 1 || Tnode == -1)break;
		node = Tnode;
	}
	
	vb queried(N+1, 0);
	queried[1] = 1;
	
	//debug(edges);
	
	int mx = *max_element(all(D));
	int qc=1;
	int rd=2;
	while((int)edges.size() < N-1 && rd <= mx){
		//debug(rd);
		//debug(edges);
		node = -1;
		int candidate=0;
		for(int i=1 ; i<=N ; ++i){
			if(D[i] == rd)++candidate;
			if(D[i] == rd && !queried[i]){
				node = i;
			}
		}
		if(node == -1){
			rd += 2;
			continue;
		}
		
		if(candidate == 1){
			for(int i=1 ; i<=N ; ++i){
				if(D[i] == rd+1 && ent.find(i) == ent.end()){
					pii P = {node, i}, rP = {i, node};
					if(edges.find(P) == edges.end() && edges.find(rP) == edges.end()){
						edges.insert(P);
						ent.insert(i);ent.insert(node);
					}
				}
				if(D[i] == rd-1){
					pii P = {node, i}, rP = {i, node};
					if(edges.find(P) == edges.end() && edges.find(rP) == edges.end()){
						edges.insert(P);
						ent.insert(i);ent.insert(node);
					}
				}
			}
			queried[node] = 1;
			continue;
		}
		
		assert(qc < (N+1) / 2);
		vi V = query(node);
		queried[node] = 1;
		++qc;
		for(int dist=1 ; ; ++dist){
			//debug(dist, node);
			int cnt=0;
			int Tnode=-1;
			for(int i=1 ; i<=N ; ++i){
				if(V[i] == dist){
					pii P = {node, i}, rP = {i, node};
					++cnt;
					if(edges.find(P) == edges.end() && edges.find(rP) == edges.end()){
						edges.insert(P);
						Tnode = i;
						ent.insert(i);ent.insert(node);
					}
				}
			}
			//debug(dist, cnt);
			//debug(edges);
			if(cnt != 1 || Tnode == -1)break;
			node = Tnode;
		}
	}
	
	cout << "!" << endl;
	for(pii P : edges)cout << P.F << " " << P.S << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cout << fixed << setprecision(10);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}

