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 f first
#define s second

typedef long long ll;
typedef pair<int, int> pi;

int n;

void query(int r, vector<int> &ans){
    cout << "? " << r << endl;
    for(int i = 1; i <= n; i++) cin >> ans[i];
}


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<int> par(n+1);
    vector<int> dist1(n+1), distcur(n+1);
    query(1,dist1);
    vector<pi> dist2;
    par[1] = -1;
    for(int i = 1; i <= n; i++){
        if(dist1[i] == 1)
            par[i] = 1;
        if(par[i] == 0) dist2.push_back({dist1[i], i});
    }
    sort(dist2.begin(), dist2.end(), greater<pi>());
    for(auto &a: dist2){
        if(par[a.s] != 0) continue;
        int cur = a.s;
        query(cur, distcur);
        vector<int> branch(dist1[cur]+1);
        for(int i = 1; i <= n; i++){
            if(dist1[i]+distcur[i] == dist1[cur]) branch[dist1[i]] = i;
        }
        for(int i = 2; i <= n; i++){
            if(dist1[i]+distcur[i] == dist1[cur]){
                par[i] = branch[dist1[i]-1];
            }else if(dist1[i]+distcur[i] == dist1[cur]+2){
                par[i] = branch[dist1[i]-1];
            }
        }
    }
    cout << "!" << "\n";
    for(int i = 2; i <= n; i++) cout << par[i] << " " << i << "\n";
    cout.flush();
    return 0;
}
