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

import sys
n = int(input())
g = [[] for i in range(n+1)]
visited = [False for i in range(n+1)]
levelArr = [[] for i in range(n+1)]
print("? 1",flush=True)
ans = [int(i) for i in input().split()]
for i in range(n):
   levelArr[ans[i]].append(i+1)
      
visited[1] = True

clvel = 0
choices = []
children = []
while clvel+1<n:
   choices = levelArr[clvel].copy()
   children = levelArr[clvel+1].copy()
   while len(choices)>0:
      choice = choices.pop(0)
      if len(choices)==0 or len(children)==0:
         visited[choice] = True
         for i in children:
            if not visited[i]:
               g[choice].append(i)
               g[i].append(choice)
               visited[i] = True
      else:
         visited[choice] = True
         print("?",choice,flush=True)
         ans = [int(i) for i in input().split()]
         for i in range(n):
            if not visited[i+1] and ans[i]==1:
               visited[i+1] = True
               g[choice].append(i+1)
               g[i+1].append(choice)
               
      #print("status",g,clvel)
   clvel+=1
#print(g)
ans = []
visited = [False for i in range(n+1)]
visited[1] = True
cnt = 0
parent = [1]
cnt = 1
while len(parent)>0:
   np = []
   for i in parent:
      visited[i] = True
      for j in g[i]:
         if not visited[j]:
            visited[j] = True
            ans.append([i,j])
            np.append(j)
            cnt+=1
   parent = np.copy()

#print(ans)

print("!",flush=True)
if n==1:
   print(1,1)
for i in ans:
   print(*i,flush=True)
#print(ans)










