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;

void solve() {
    int n;
    cin >> n;
    
    int d[n];
    set<int> graph[n];
    vector<bool> vis(n, false);
    
    queue<int> q;
    q.push(0);
    
    while(!q.empty()) {
        int i = q.front();
        q.pop();
        
        if(vis[i]) {
            continue;
        }
        vis[i] = true;
        
        cout << "? " << i + 1 << endl;
        cout.flush();
        
        
        int ct = 0;
        int parent = -1;
        for(int j = 0; j < n; j++) {
            cin >> d[j];
            if(d[j] == 1) {
                graph[j].insert(i);
                graph[i].insert(j);
                vis[j] = true;
                ct++;
                parent = j;
            } else if(d[j] == 2) {
                if(!vis[j]) {
                    q.push(j);
                }
            }
        }
        if(ct == 1) {
            for(int j = 0; j < n; j++) {
                if(d[j] == 2) {
                    graph[parent].insert(j);
                    graph[j].insert(parent);
                    vis[j] = true;
                } else if(d[j] == 3) {
                    if(!vis[j]) {
                        q.push(j);
                    }
                }
            }
        }
        
    }
    cout << "!" << endl;
    cout.flush();
    vector<bool> vis2(n, false);
    for(int i = 0; i < n; i++) {
        for(auto x: graph[i]) {
            if(vis2[x] != true) {
                cout << i + 1 << " " << x + 1 << endl;
                cout.flush();
            }
        }
        vis2[i] = true;
    }
    return;
}

int main() {
    solve();
    return 0;
}