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

def query(node):
    print("?", node+1)
    return list(map(int, input().split()))


n = int(input())

ans = query(0)  # root at node 0
max_depth = max(ans)
depths = [set() for _ in range(max_depth+1)]
for node, depth in enumerate(ans):
    depths[depth].add(node)
num_even_depths = sum(len(depths[i]) for i in range(2, len(depths), 2))  # not counting 0
num_odd_depths = sum(len(depths[i]) for i in range(1, len(depths), 2))

graph = {0: depths[1]}
for node in depths[1]:
    graph[node] = set()
for depth in range(2 if num_even_depths < num_odd_depths else 1, max_depth+1, 2):
    for node in depths[depth]:
        ans = query(node)
        neighbors = {i for i in range(n) if ans[i] == 1}
        parent = {i for i in neighbors if i in depths[depth-1]}.pop()
        graph[parent].add(node)
        neighbors.remove(parent)
        children = neighbors
        graph[node] = children
        for child in children:
            graph[child] = set()

print("!")
for node in graph:
    for child in graph[node]:
        print(node+1, child+1)