This is an interactive problem.

Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of n nodes! The nodes of the tree are numbered from 1 to n.

The game master only allows him to ask one type of question:

  * Little Dormi picks a node r (1 ≤ r ≤ n), and the game master will reply with an array d_1, d_2, …, d_n, where d_i is the length of the shortest path from node r to i, for all 1 ≤ i ≤ n.



Additionally, to make the game unfair challenge Little Dormi the game master will allow at most ⌈n/2⌉ questions, where ⌈ x ⌉ denotes the smallest integer greater than or equal to x.

Faced with the stomach-churning possibility of not being able to guess the tree, Little Dormi needs your help to devise a winning strategy!

Note that the game master creates the tree before the game starts, and does not change it during the game.

Input

The first line of input contains the integer n (2 ≤ n ≤ 2 000), the number of nodes in the tree.

You will then begin interaction.

Output

When your program has found the tree, first output a line consisting of a single "!" followed by n-1 lines each with two space separated integers a and b, denoting an edge connecting nodes a and b (1 ≤ a, b ≤ n). Once you are done, terminate your program normally immediately after flushing the output stream.

You may output the edges in any order and an edge (a,b) is considered the same as an edge (b,a). Answering is not considered as a query.

Interaction

After taking input, you may make at most ⌈n/2⌉ queries. Each query is made in the format "? r", where r is an integer 1 ≤ r ≤ n that denotes the node you want to pick for that query.

You will then receive n space separated integers d_1, d_2, …, d_n, where d_i is the length of the shortest path from node r to i, followed by a newline.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++; 
  * System.out.flush() in Java; 
  * flush(output) in Pascal; 
  * stdout.flush() in Python; 
  * see documentation for other languages. 



If at any point you make an invalid query or try to make more than ⌈ n/2 ⌉ queries, the interaction will terminate immediately and you will receive a Wrong Answer verdict.

Hacks

To hack a solution, use the following format.

The first line contains the integer n (2 ≤ n ≤ 2 000).

The next n−1 lines contain two integers u and v (1 ≤ u,v ≤ n) denoting an edge between u and v (u ≠ v). These n-1 edges must form a tree.

Examples

Input


4

0 1 2 2

1 0 1 1

Output


? 1

? 2

!
4 2
1 2
2 3


Input


5

2 2 1 1 0


Output


? 5

!
4 5
3 5
2 4
1 3

Note

Here is the tree from the first example.

<image>

Notice that the edges can be output in any order.

Additionally, here are the answers for querying every single node in example 1:

  * 1: [0,1,2,2] 
  * 2: [1,0,1,1] 
  * 3: [2,1,0,2] 
  * 4: [2,1,2,0]



Below is the tree from the second example interaction.

<image>

Lastly, here are the answers for querying every single node in example 2:

  * 1: [0,4,1,3,2] 
  * 2: [4,0,3,1,2] 
  * 3: [1,3,0,2,1] 
  * 4: [3,1,2,0,1] 
  * 5: [2,2,1,1,0]

Source: codeforces | Difficulty: UNKNOWN_DIFFICULTY
Tags: Tree algorithms

Constructive algorithms


Solutions:
res = []
n = int(input())
print('?', 1, flush=True)
arr = list(map(int, input().split()))
for (v, d) in enumerate(arr):
	if d == 1:
		res.append([0, v])
one = [v for (v, d) in enumerate(arr) if d & 1]
two = [v for (v, d) in enumerate(arr) if v and (not d & 1)]
if len(one) > len(two):
	(one, two) = (two, one)
for u in one:
	print('?', u + 1, flush=True)
	arr = list(map(int, input().split()))
	for (v, d) in enumerate(arr):
		if d == 1 and v:
			res.append([u, v])
print('!')
for (u, v) in res:
	print(u + 1, v + 1)


import sys
input = sys.stdin.readline
flush = sys.stdout.flush

def query(x):
	print('?', x)
	flush()
	return list(map(int, input().split()))
n = int(input())
ans = set()
A = query(1)
(X, Y) = ([], [])
for (i, a) in enumerate(A, 1):
	if not a % 2:
		X.append(i)
	else:
		Y.append(i)
if len(X) > len(Y):
	(X, Y) = (Y, X)
for x in X:
	if x != 1:
		B = query(x)
	else:
		B = A
	for (i, b) in enumerate(B, 1):
		if b == 1:
			ans.add((x, i))
print('!')
flush()
for a in ans:
	print(*a)
	flush()


import sys
input = sys.stdin.readline

def ask(i):
	print(f'? {i + 1}', flush=True)
	return list(map(int, input().split()))

def main():
	n = int(input())
	ans = []
	dlst = ask(0)
	odd = []
	even = []
	for (i, d) in enumerate(dlst):
		if d % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	if len(even) <= len(odd):
		for (i, d) in enumerate(dlst):
			if d == 1:
				ans.append((1, i + 1))
	else:
		even = odd.copy()
	for i in even:
		if i == 0:
			continue
		dlst = ask(i)
		for (j, d) in enumerate(dlst):
			if d == 1:
				ans.append((i + 1, j + 1))
	print('!')
	for row in ans:
		print(*row)
for _ in range(1):
	main()


import sys
from sys import stdout
import io, os
input = lambda : sys.stdin.readline().strip()
P = lambda : list(map(int, input().split()))
from math import factorial as f, gcd
from collections import deque, defaultdict as dd, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
from random import randint, choice, sample
import time
mod = 10 ** 9 + 7
a = ord('a')
start = time.time()

def fast_exp(x, exp):
	ans = 1
	base = x
	while exp:
		if exp & 1:
			ans *= base
		base *= base
		base %= mod
		ans %= mod
		exp >>= 1
	return ans

def countBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def submasks(n):
	org = n
	while n:
		yield n
		n = n - 1 & org

def query(i):
	print('?', i + 1)
	stdout.flush()
	return P()

def solve():
	n = int(input())
	mat = [[0] * n for _ in range(n)]
	start = query(0)
	for (i, x) in enumerate(start):
		if x == 1:
			mat[i][0] = 1
			mat[0][i] = 1
	odd = sum([i % 2 for i in start[1:]])
	even = n - 1 - odd
	if odd < even:
		for (i, x) in enumerate(start):
			if x % 2:
				temp = query(i)
				for (j, y) in enumerate(temp):
					if y == 1:
						mat[i][j] = 1
						mat[j][i] = 1
	else:
		for (i, x) in enumerate(start):
			if x % 2 == 0 and x:
				temp = query(i)
				for (j, y) in enumerate(temp):
					if y == 1:
						mat[i][j] = 1
						mat[j][i] = 1
	print('!')
	for i in range(n):
		for j in range(i + 1, n):
			if mat[i][j]:
				print(i + 1, j + 1)
solve()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = int(input())

	def query(r):
		print('?', r + 1, flush=True)
		return [int(i) for i in input().split()]
	d = query(0)
	parity = 1 - (sum((i % 2 == 0 for i in d)) <= (n + 1) // 2)
	done = set()
	sol = [[0, 0] for _ in range(n - 1)]
	idx = 0
	if parity == 0:
		done.add(0)
		for (i, di) in enumerate(d):
			if di == 1:
				sol[idx] = [0, i]
				idx += 1
	for (i, di) in enumerate(d):
		if di % 2 == parity and i != 0:
			for (j, k) in enumerate(query(i)):
				if k == 1:
					sol[idx] = [i, j]
					idx += 1
	print('!')
	for edge in sol:
		print(*[i + 1 for i in edge])
	print(end='', flush=True)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math

def inpu():
	return sys.stdin.readline()

def Q(m):
	print('?', m + 1)
	sys.stdout.flush()
	return map(int, input().split())
n = int(input())
done = False
if n == 2:
	print('!')
	print(1, 2)
else:
	stag = [0] * n
	st_v = [0] * n
	ed = set()
	r = Q(0)
	i = 0
	for j in r:
		if not stag[j]:
			st_v[j] = {i}
		stag[j] += 1
		st_v[j].add(i)
		i += 1
	o = 0
	oi = 0
	e = 0
	ei = 0
	lstag = len(stag)
	for i in range(1, lstag):
		if i % 2:
			o += stag[i]
			oi += 1
		else:
			e += stag[i]
			ei += 1
	if e < o:
		for i in st_v[1]:
			ed.add((1, i + 1))
	if o <= e:
		j0 = 1
	else:
		j0 = 2
	while j0 < n and stag[j0]:
		for i0 in st_v[j0]:
			r = Q(i0)
			iii = 1
			for i in r:
				if i == 1:
					ed.add((i0 + 1, iii))
				iii += 1
		j0 += 2
	print('!')
	for i in ed:
		print(i[0], i[1])


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	n = vary(1)
	print('? 1', flush=True)
	dis = array_int()
	tree = [[] for i in range(n + 1)]
	nodes = [1] * (n + 1)
	for i in range(len(dis)):
		if dis[i] % 2 != 0:
			if dis[i] == 1:
				tree[1].append(i + 1)
			nodes[i + 1] = 0
		else:
			nodes[i + 1] = 1
	white = nodes.count(0)
	black = nodes.count(1) - 1
	if black <= white:
		for i in range(2, n + 1):
			if nodes[i] == 1:
				print('?', i, flush=True)
				dis = array_int()
				for j in range(len(dis)):
					if dis[j] == 1:
						tree[i].append(j + 1)
	else:
		for i in range(1, n + 1):
			if nodes[i] == 0:
				print('?', i, flush=True)
				dis = array_int()
				for j in range(len(dis)):
					if dis[j] == 1:
						tree[i].append(j + 1)
	print('!', flush=True)
	st = set()
	for i in range(1, n + 1):
		for j in tree[i]:
			if (i, j) not in st and (j, i) not in st:
				print(i, j, flush=True)
				st.add((i, j))
				st.add((j, i))


def query(node):
	print('?', node + 1)
	return list(map(int, input().split()))
n = int(input())
ans = query(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)))
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)


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def solve(a):
	for i in a:
		if i == 1:
			continue
		print('?', i, flush=True)
		a1 = list(map(int, input().split()))
		for (j, v) in enumerate(a1):
			if v == 1:
				ans.add((max(i, j + 1), min(i, j + 1)))
n = int(input())
print('?', 1, flush=True)
a1 = list(map(int, input().split()))
a = []
b = []
ans = set()
for (i, v) in enumerate(a1):
	if v == 1:
		ans.add((i + 1, 1))
	if v % 2:
		a.append(i + 1)
	else:
		b.append(i + 1)
if len(a) < len(b):
	solve(a)
else:
	solve(b)
print('!', flush=True)
for i in ans:
	print(*i, flush=True)


from sys import stdin, stdout
input = stdin.readline

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())
edges = []

def add_edges(i, d):
	for j in range(len(d)):
		if d[j] == 1:
			edges.append((i, j + 1))
n = inp()
print('? 1')
stdout.flush()
d = inlt()
levels = []
for i in range(max(d) + 1):
	levels.append([])
for i in range(len(d)):
	levels[d[i]].append(i + 1)
num_evens = 0
for i in range(0, len(levels), 2):
	num_evens += len(levels[i])
if num_evens <= n // 2:
	add_edges(1, d)
	for i in range(2, len(levels), 2):
		for j in levels[i]:
			print(f'? {j}')
			stdout.flush()
			d = inlt()
			add_edges(j, d)
else:
	for i in range(1, len(levels), 2):
		for j in levels[i]:
			print(f'? {j}')
			stdout.flush()
			d = inlt()
			add_edges(j, d)
print('!')
for e in edges:
	print(f'{e[0]} {e[1]}')


import sys
from collections import deque

def get(i):
	print('?', i + 1)
	return list(map(int, input().split()))
n = int(input())
e = set()
c = 0
z = get(0)
odd = 0
even = 0
for (i, x) in enumerate(z):
	if x == 0:
		continue
	if x & 1:
		odd += 1
	else:
		even += 1
	if x == 1:
		e.add((0, i))
if odd < even:
	for (i, x) in enumerate(z):
		if x & 1 == 0:
			continue
		z2 = get(i)
		for (j, y) in enumerate(z2):
			if y == 1:
				e_ = (min(i, j), max(i, j))
				e.add(e_)
else:
	for (i, x) in enumerate(z):
		if x & 1 == 1 or i == 0:
			continue
		z2 = get(i)
		for (j, y) in enumerate(z2):
			if y == 1:
				e_ = (min(i, j), max(i, j))
				e.add(e_)
print('!')
for E in e:
	print(E[0] + 1, E[1] + 1)
sys.stdout.flush()


def f(n):
	if n == 2:
		print('!')
		print('1 2')
		return
	edges = set()
	print('? 1')
	xs = [int(x) for x in input().split()]
	for (i, x) in enumerate(xs):
		if x == 1:
			edges.add((1, i + 1))
	parity = [0, 0]
	for x in xs:
		if x > 0:
			parity[x % 2] += 1
	p = 1 if parity[0] > parity[1] else 0
	for (i, x) in enumerate(xs):
		if i > 0 and x % 2 == p:
			print('?', i + 1)
			ys = [int(y) for y in input().split()]
			for (j, y) in enumerate(ys):
				if y == 1:
					if i < j:
						edges.add((i + 1, j + 1))
					else:
						edges.add((j + 1, i + 1))
	print('!')
	for (x, y) in edges:
		print(x, y)
f(int(input()))


N = int(input())
if N == 2:
	print('!')
	print(1, 2)
	exit()
ANS = set()

def ha(i, j):
	if i > j:
		(i, j) = (j, i)
	return (i << 20) + j

def addans(i, j):
	if i == j:
		return
	ANS.add(ha(i, j))

def ask(i):
	print('?', i + 1)
	L = [int(a) for a in input().split()]
	for (j, a) in enumerate(L):
		if a == 1:
			addans(i, j)
	return L
A = ask(0)
e = 0
o = 0
E = []
O = []
for (i, a) in enumerate(A):
	if i == 0:
		continue
	if a % 2:
		o += 1
		O.append(i)
	else:
		e += 1
		E.append(i)
if o >= e:
	for i in E:
		ask(i)
else:
	for i in O:
		ask(i)
print('!')
mmm = (1 << 20) - 1
for ij in ANS:
	i = ij >> 20
	j = ij & mmm
	print(i + 1, j + 1)


def answer():
	print('?', 1)
	d = list(map(int, input().split()))
	edges = []
	(even, odd) = ([], [])
	for i in range(len(d)):
		if d[i] & 1:
			if i + 1 != 1:
				odd.append(i + 1)
		elif i + 1 != 1:
			even.append(i + 1)
		if d[i] == 1:
			edges.append([1, i + 1])
	if len(even) < len(odd):
		for i in even:
			print('?', i)
			d = list(map(int, input().split()))
			for j in range(len(d)):
				if j + 1 != 1 and d[j] == 1:
					edges.append([i, j + 1])
	else:
		for i in odd:
			print('?', i)
			d = list(map(int, input().split()))
			for j in range(len(d)):
				if j + 1 != 1 and d[j] == 1:
					edges.append([i, j + 1])
	print('!')
	for x in edges:
		print(*x)
n = int(input())
answer()


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(n):
	print(f'? {1}')
	sys.stdout.flush()
	result = [int(i) for i in parse_input().split()]
	even = set()
	odd = set()
	edges = set()
	for (i, val) in enumerate(result):
		if val == 1:
			edges.add((1, i + 1))
		if val > 0 and val % 2 == 0:
			even.add(i + 1)
		if val % 2 == 1:
			odd.add(i + 1)
	if len(even) < len(odd):
		choose = even
	else:
		choose = odd
	while choose:
		node = choose.pop()
		print(f'? {node}')
		sys.stdout.flush()
		result = [int(i) for i in parse_input().split()]
		for (i, val) in enumerate(result):
			if val == 1:
				edges.add(tuple(sorted([node, i + 1])))
	return edges

def main():
	n = int(parse_input())
	edges = func(n)
	print('!')
	for val in edges:
		print(f'{val[0]}  {val[1]}')
	sys.stdout.flush()
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
n = int(input())
i = 1
print('?', 1)
b = list(map(int, input().split()))
even = []
odd = []
arr = set()
for x in range(len(b)):
	if b[x] % 2 == 0 and b[x] != 0:
		even.append(x + 1)
	elif b[x] % 2 == 1:
		odd.append(x + 1)
	if b[x] == 1:
		arr.add((max(x + 1, 1), min(x + 1, 1)))
q = []
if len(even) > len(odd):
	q = odd
else:
	q = even
while q and i + 1 <= math.ceil(n / 2):
	tmp = q.pop(-1)
	print(f'? {tmp}')
	b = list(map(int, input().split()))
	for x in range(len(b)):
		if b[x] == 1:
			arr.add((max(tmp, x + 1), min(tmp, x + 1)))
	i += 1
print('!')
for x in arr:
	print(x[0], x[1])


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
print('? 1', flush=True)
a = list(map(int, input().split()))
even = []
odd = []
ans = set()
for i in range(1, len(a)):
	if a[i] % 2 == 0:
		even.append(i + 1)
	else:
		odd.append(i + 1)
	if a[i] == 1:
		ans.add((1, i + 1))
if len(odd) < len(even):
	for i in range(len(odd)):
		print('?', odd[i], flush=True)
		a = list(map(int, input().split()))
		for j in range(len(a)):
			if a[j] == 1:
				ans.add((min(odd[i], j + 1), max(odd[i], j + 1)))
else:
	for i in range(len(even)):
		print('?', even[i], flush=True)
		a = list(map(int, input().split()))
		for j in range(len(a)):
			if a[j] == 1:
				ans.add((min(even[i], j + 1), max(even[i], j + 1)))
ans = list(ans)
print('!')
for i in ans:
	print(*i, sep=' ')


import sys
import io, os
input = sys.stdin.buffer.readline
n = int(input())
edge = set()
print('?', 1, flush=True)
D = list(map(int, input().split()))
E = []
O = []
for (i, d) in enumerate(D):
	if i == 0:
		continue
	if d % 2 == 0:
		E.append(i)
	else:
		O.append(i)
	if d == 1:
		edge.add((1, i + 1))
if len(E) < len(O):
	Q = E
else:
	Q = O
for i in Q:
	print('?', i + 1, flush=True)
	D = list(map(int, input().split()))
	for (j, d) in enumerate(D):
		if d == 1:
			v = min(i + 1, j + 1)
			u = max(i + 1, j + 1)
			edge.add((v, u))
print('!', flush=True)
for (u, v) in edge:
	print(u, v, flush=True)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	tree = []
	odd = []
	even = []
	print('? 1', flush=True)
	arr = list(map(int, input().split()))
	for (i, item) in enumerate(arr):
		if item & 1:
			odd.append(i + 1)
		else:
			even.append(i + 1)
	ans = list()
	if len(odd) < len(even):
		ans = odd
	else:
		ans = even
	for i in ans:
		if i != 1:
			print(f'? {i}', flush=True)
			arr = list(map(int, input().split()))
		for (j, item) in enumerate(arr):
			if item == 1:
				tree.append((i, j + 1))
	print('!')
	for item in tree:
		print(*item)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def readline():
	return map(int, input().split())

def ask(r):
	assert r >= 0
	print('?', r + 1)
	return list(readline())

def say(edges):
	print('!')
	for (a, b) in edges:
		print(a + 1, b + 1)

def main():
	n = int(input())
	d0 = ask(0)
	cnt = [0, 0]
	for value in d0:
		cnt[value & 1] += 1
	b = 1 if cnt[0] > cnt[1] else 0
	edges = list()
	for (i, value) in enumerate(d0):
		if value & 1 == b:
			di = ask(i) if i != 0 else d0
			edges.extend(((i, j) for (j, vj) in enumerate(di) if vj == 1))
	say(edges)
main()