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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int dis[2005];
int d[2005];
int father[2005];
bool vis[2005];
int p[2005];
bool cmp(int a,int b)
{
    return dis[a]<dis[b];
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("? %d\n",1);
    fflush(stdout);
    for(int i=1;i<=n;i++)
        scanf("%d",&dis[i]);
    for(int i=1;i<=n;i++)
        if(dis[i]==1)
        {
            father[i]=1;
            vis[1]=true;
        }
    for(int i=1;i<=n;i++)
        p[i]=i;
    sort(p+1,p+n+1,cmp);
    for(int i=2;i<=n;i++)
        if(!father[p[i]]&&!vis[p[i]])
        {
            printf("? %d\n",p[i]);
            fflush(stdout);
            for(int j=1;j<=n;j++)
                scanf("%d",&d[j]);
            for(int j=1;j<=n;j++)
                if(d[j]==1&&dis[p[i]]-dis[j]==1)
                {
                    father[p[i]]=j;
                    vis[j]=true;
                }
            for(int j=1;j<=n;j++)
                if(d[j]==1&&dis[j]-dis[p[i]]==1)
                {
                    father[j]=p[i];
                    vis[p[i]]=true;
                }
            for(int j=1;j<=n;j++)
                if(d[j]==2&&dis[j]==dis[p[i]])
                {
                    father[j]=father[p[i]];
                    vis[father[p[i]]]=true;
                }
        }
    printf("!\n");
    for(int i=2;i<=n;i++)
        printf("%d %d\n",father[i],i);
    fflush(stdout);
    return 0;
}
