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 collections import deque
def get(i):
    print("?", i+1)
    return list(map(int, input().split()))
n = int(input())
e = []
c = 0
done = set()
N = deque()
N.append(0)
pr_ones = set()
while N:
    if len(e) == n - 1:
        break
    c = N.popleft()
    if c in done:
        continue
    z = get(c)
    ones = []
    twos = []
    for i, x in enumerate(z):
        if i in done:
            continue
        if x == 1:
            e.append((i, c))
            if i not in pr_ones:
                ones.append(i)
            else:
                done.add(i)
        elif x == 2:
            twos.append(i)
    pr_ones = set(ones)
    done.add(c)
    if len(ones) < len(twos):
        for x in ones:
            N.append(x)
    else:
        for x in twos:
            N.append(x)
assert len(e) == n - 1
print("!")
for E in e:
    print(E[0] + 1, E[1] + 1)
sys.stdout.flush()
