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

// way to candy :)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void run(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int N=5e5+5;
void solve(){
    int n;
    cin>>n;
    bool vis[n+1]={0};
    map<pair<int,int>,bool> mp;
    vector<pair<int,int>> ans;
    int last=1;
    int x=1;
    while(ans.size()+1<n)
    {
        vector<pair<int,int>>p;
        int freq[n+1]={0};
        cout<<"? "<<x<<'\n';
        cout.flush();
        for (int j = 0; j < n; ++j)
        {
            int d;
            cin>>d;
            freq[d]++;
            p.push_back({d,j+1});
        }
        sort(p.begin(), p.end());
        int ls=-1;
        for (int j = 1; j < n; ++j)
        {
            if(p[j].first!=p[j-1].first)
                ls=p[j-1].second;
            if(freq[p[j].first-1]==1&&!mp[{ls,p[j].second}]&&!mp[{ls,p[j].second}]){
                ans.push_back({ls,p[j].second});
                mp[{ls,p[j].second}]=1;
                vis[ls]=1;
            }
        }
        int z=n-1;
        while(z>=0){
            if(!vis[p[z].second]){
                x=p[z].second;
                break;
            }
            z--;
        }
    }
    cout<<"!\n";
    for(auto i:ans){
        cout<<i.first<<' '<<i.second<<'\n';
    }
}
int main()
{
    run();
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
/*
1 2 3 4
4 3 2 1
*/