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 int long long int

using namespace std;

const int N = 1e5 + 5;

int dis[2005][2005];
int done[2005][2005];
vector<int> g[2005];

void ask(int i)
{
    cout << "? " << i << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    ask(1);
    for(int i=1;i<=n;i++)
        cin>>dis[1][i];
    vector<int> odd;
    vector<int> even;
    for(int i=2;i<=n;i++)
    {
        if(dis[1][i] % 2)
            odd.push_back(i);
        else
            even.push_back(i);
        if(dis[1][i] == 1)
        {
            g[1].push_back(i);
            g[i].push_back(1);
            done[i][1] = done[1][i] = 1;
        }
    }
    if(odd.size() > even.size())
        swap(even,odd);
    for(auto x : odd)
    {
        ask(x);
        for(int i=1;i<=n;i++)
        {
            int v;
            cin>>v;
            if(v == 1 && !done[x][i])
            {
                g[x].push_back(i);
                g[i].push_back(x);
                done[x][i] = 1;
                done[i][x] = 1;
            }
        }
    }
    cout << "!" << endl;
    for(int i=1;i<=n;i++)
    {
        for(auto x : g[i])
        {
            if(done[x][i] == 2)
                continue;
            cout << x << " " << i << endl;
            done[x][i] = done[i][x] = 2;
        }
    }
}
