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 java.util.*;
import java.lang.*;
import java.io.*;

public class feb20 {

	public static void main(String[] srgs) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
		String[] scn = (br.readLine()).trim().split(" ");
		int n = Integer.parseInt(scn[0]);

		graph = new ArrayList<>();
		for (int i = 0; i <= n; i++) {
			graph.add(new ArrayList<>());
		}
		arr = ask(0, n);
		int par = -1;
		pre(n);
		int src = 0;
		if (off > set) {
			askset(n);
		} else {
			askoff(n);
		}
		dfs(graph, new boolean[n + 1], src, par);

		sb.append("\n");
		System.out.print(sb);
		return;

	}

	private static void askset(int n) throws Exception {
		ArrayList<Integer> child = new ArrayList<>();
		int ans = 0;
		int i = 1;
		while (i < n) {
			int tot = 1;
			for (int j = 0; j < n; j++) {
				if (arr[j] == i) {
					int[] res = ask(j, n);
					tot += 1;
					for (int k = 0; k < n; k++) {
						if (res[k] == 1) {
							tot -= 1;
							graph.get(j).add(k);
							graph.get(k).add(j);
						}
					}
					ans += tot;
				}
				if (ans < 2)
					tot -= 1;
			}
			i += 2;
		}

	}

	
	static StringBuilder sb;

	public static void debug() {
		System.out.println("working..");
	}

	public static void debug(int i) {
		System.out.println("working on " + i);
	}

	public static void askoff(int n) throws Exception {
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == 1) {
				count += 1;
				graph.get(0).add(i);
				count += 1;
				graph.get(i).add(0);
			}
		}
		int tot = count;
		ArrayList<Integer> child = new ArrayList<>();
		int ans = 0;
		int i = 1;
		while (i < n) {
			ans += 1;
			for (int j = 0; j < n; j++) {
				if (arr[j] == i) {
					tot += 2;
					int[] res = ask(j, n);
					for (int k = 0; k < n; k++) {
						if (res[k] == 1) {
							tot += 1;
							graph.get(j).add(k);
							tot += 1;
							graph.get(k).add(j);
						}
					}
					if (ans < tot) {
						ans += tot;
					}
				}
			}
			i += 2;
		}

	}

	private static void pre(int n) {
		for (int i = 0; i < n; i++) {
			if ((arr[i] & 1) != 0) {
				set++;
			} else {
				off++;
			}
		}
	}

	static int off;
	static int[] arr;
	static int set;
	static ArrayList<ArrayList<Integer>> graph;

	public static void sort(long[] arr) {
		int n = arr.length;
		for (int i = 0; i < n; i++) {
			int idx = (int) Math.random() * n;
			long temp = arr[i];
			arr[i] = arr[idx];
			arr[idx] = temp;
		}

		Arrays.sort(arr);
	}

	public static void sort(int[] arr) {
		int n = arr.length;
		for (int i = 0; i < n; i++) {
			int idx = (int) Math.random() * n;
			int temp = arr[i];
			arr[i] = arr[idx];
			arr[idx] = temp;
		}
		Arrays.sort(arr);
	}

	private static int[] ask(int ele, int n) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("? " + ele);
		System.out.flush();
		int[] arr = new int[n];
		String[] scn = br.readLine().trim().split(" ");
		scn = (br.readLine()).trim().split(" ");
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(scn[i]);
		}
		return arr;
	}

	public static void sec() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();
		while (t-- > 0) {
			String[] scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}
			sb.append("\n");
		}
		System.out.println(sb);
		return;

	}

	public static void third() throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] scn = (br.readLine()).trim().split(" ");
		int n = Integer.parseInt(scn[0]);
		long[] arr = new long[n];
		scn = (br.readLine()).trim().split(" ");
		for (int i = 0; i < n; i++) {
			arr[i] = Long.parseLong(scn[i]);
		}
		System.out.println(sb);
		return;

	}

	public static void dfs(ArrayList<ArrayList<Integer>> graph, boolean[] vis, int src, int par) {
		vis[src] = true;
		boolean leaf = true;
		for (int nn : graph.get(src)) {

			if (nn == par)
				continue;
			leaf = false;
			sb.append((src + 1) + " " + (nn + 1 )+ "\n");
			dfs(graph, vis, nn, src);
		}
	}

	public static void print(long[][] dp) {
		for (long[] a : dp) {
			for (long ele : a) {
				System.out.print(ele + " ");
			}
			System.out.println();
		}
	}

	public static void print(int[][] dp) {
		for (int[] a : dp) {
			for (int ele : a) {
				System.out.print(ele + " ");
			}
			System.out.println();
		}
	}

	public static void print(boolean[] dp) {
		for (boolean ele : dp) {
			System.out.print(ele + " ");
		}
		System.out.println();
	}

	public static void print(long[] dp) {
		for (long ele : dp) {
			System.out.print(ele + " ");
		}
		System.out.println();
	}

}
