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

const ll MOD = 1e9+7;

set<pair<int, int>> edges;
int n;

vector<int> ask(int r) {
    cout << "? " << r+1 << endl;
    vector<int> res(n);
    for (int i = 0; i < n; ++i) cin >> res[i];
    return res;
}


void print() {
    cout << "!" << endl;
    for (auto edge : edges) {
        cout << edge.first+1 << ' ' << edge.second+1 << endl;
    }
    fflush(stdout);
}

vector<int> bin[2005];
int dp[2005];

void solve () {
    cin >> n;
    vector<int> d = ask(0);
    int diam = *max_element(d.begin(), d.end());
    for (int i = 0; i < n; ++i) {
        if (d[i] == 1) {
            edges.insert({0, i});
        } 
        bin[d[i]].push_back(i);
    }
    int sum = 0;
    for (int i = 0; i <= diam; i += 2) sum += bin[i].size();
    if (sum - 1 <= n - sum) {
        for (int i = 0; i <= diam; i += 2) {
            if (i == 0) continue;
            for (int x : bin[i]) {
                vector<int> d2 = ask(x);
                for (int j = 0; j < n; ++j) {
                    if (d2[j] == 1) {
                        edges.insert({x, j});
                    }
                }
            }
        }
    } else {
        for (int i = 1; i <= diam; i += 2) {
            for (int x : bin[i]) {
                vector<int> d2 = ask(x);
                for (int j = 1; j < n; ++j) {
                    if (d2[j] == 1) {
                        edges.insert({x, j});
                    }
                }
            }
        }
    }
    print();
    return;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while(t--) solve();
}

