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>

#define fi first
#define se second
#define ll long long
#define dl double

using namespace std;

const int N = 2e3 + 7;
const long long mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int a[N][N];

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

void solve()
{
        cin >> n;
        auto x = ask(1);
        vector<int> lvl[2][n + 1];
        int s1 = 0, s2 = 0;
        int st = 0;
        for(int i = 2; i <= n; i++){
                if(x[i] == 1){
                        a[i][1] = 1;
                }
                lvl[x[i] % 2][x[i]].push_back(i);
                if(x[i] % 2)s1++;
                else s2++;
        }
        if(s1 < s2)st = 1;
        for(int i = 1; i <= n; i++){
                if(!lvl[st][i].empty()){
                        for(auto x : lvl[st][i]){
                                auto y = ask(x);
                                for(int j = 1; j <= n; j++){
                                        if(y[j] == 1){
                                                a[x][j] = 1;
                                        }
                                }
                        }
                }
        }
        cout << "!" << endl;
        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= n; j++){
                        if(a[i][j]){
                                cout << i << " " << j << endl;
                                a[i][j] = a[j][i] = 0;
                        }
                }
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
