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 math
import heapq
import sys
import bisect
from collections import deque
import time
input = sys.stdin.readline
mod=10**9+7
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
def hash(x,y,n):
    return(x+n*(y-1))
n=inp()
x=[]
edge={}
e=1
v=[0]*n
x=0
for i in range(math.ceil(n/2)):
    print("?",e,flush=1)
    l=inlt()
    d={}
    y=[]
    for i in range(n):
        heapq.heappush(y,(-1*l[i],i+1))
    for i in range(n):
        d[i]=[]
    for i in range(n):
        d[l[i]].append(i+1)
    d[n]=[]
    for i in d:
        if i!=n-1 and i!=n:
            if len(d[i])==1 and not v[d[i][0]-1] and len(d[i+1])!=0:
                v[d[i][0]-1]=1
                for j in d[i+1]:
                    if hash(min(d[i][0],j),max(d[i][0],j),n) not in edge:
                        x+=1
                        edge[hash(min(d[i][0],j),max(d[i][0],j),n)]=[min(d[i][0],j),max(d[i][0],j)]
    if x==n-1:
        break
    #for i in range(n):
    #    l[i]=[l[i],i]
    #l.sort(reverse=1)
    for i in range(n):
        a=heapq.heappop(y)
        if not v[a[1]-1]:
            e=a[1]
            break
if x!=n-1:
    print(x)
print("!",flush=1)
for i in edge:
    print(*edge[i],flush=1)
