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
from sys import stdin, stdout
input, print = stdin.readline, stdout.write
from collections import OrderedDict, defaultdict

adj = defaultdict(list)
vis = defaultdict(int)
inq = defaultdict(int)
n = int(input())
unv = n

def qry(r):
    global adj, vis, q, n, unv
    print("? ")
    print(str(r+1))
    print('\n')
    stdout.flush()
    d = [*map(int, input().split())]
    a = []
    b = []
    for i in range(len(d)):
        if d[i] == 1 and inq[i] == 0:
            a.append(i)
        if d[i] == 2 and inq[i] == 0:
            b.append(i)
    # hsh = defaultdict(list)
    # for i in range(len(d)):
        # if inq[i] == 0:
            # hsh[d[i]].append(i)
    # for x in hsh[d[1]]:
        # unv -= 1
    for x in a:
        adj[x].append(r)
        adj[r].append(x)
    # print(str(a))
    if len(b) <= len(a):
        for x in b:
            q.append(x)
    else:
        for x in a:
            q.append(x)

q = [0]
while len(q) > 0 and unv > 0:
    v = q.pop(0)
    if inq[v] == 1: continue
    vis[v] = 1
    inq[v] = 1
    unv -= 1
    qry(v)

print('!\n')
done = defaultdict(set)
for i in range(n):
    for x in adj[i]:
        if i in done[x]:
            continue
        print(str(i + 1))
        print(' ')
        print(str(x + 1))
        print('\n')
        done[x].add(i)
        done[i].add(x)
stdout.flush()

# for x in adj:
#     print(str(adj))
#     print('\n')
# print(str(adj))
# print('\n')
# print(str(vis))