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.Scanner;
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
public class Solution
{	
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args)
	{
		int numNodes = Integer.parseInt(scan.nextLine());
		HashSet<String> answers = new HashSet<String>();
		
		//Pick node 1 : root
		int[] nodes = query(1, scan);

		ArrayList<ArrayList<Integer>> layers = new ArrayList<ArrayList<Integer>>();
		int maxx = max(nodes);
		for (int i = 0; i < maxx; i++)
		{
			layers.add(new ArrayList<Integer>());
		}
		for (int i = 2; i <= numNodes; i++)
		{
			layers.get(nodes[i-1] - 1).add(i);
		}

		int evenNodes = 0;
		for (int i = 0; i < maxx; i+=2)
		{
			evenNodes += layers.get(i).size();
		}

		if (maxx == 1)
		{
			for (int i = 2; i <= numNodes; i++)
			{
				answers.add("1 " + Integer.toString(i));
			}
		}
		else if (evenNodes >= numNodes - evenNodes)
		{
			for (int node : layers.get(0))
				answers.add("1 " + Integer.toString(node));
			
			for (int i = 1; i <  layers.size(); i += 2)
			{
				addLayer(i, layers, answers);
			}
		}
		else if (evenNodes < numNodes - evenNodes)
		{
			for (int node : layers.get(0))
				answers.add("1 " + Integer.toString(node));
			
			for (int i = 0; i < layers.size(); i += 2)
			{
				addLayer(i, layers, answers);
			}
		}
		System.out.println("!");
		for (String s : answers)
		{
			System.out.println(s);
		}
		System.out.flush();
	}
	
	public static void addLayer(int layer, ArrayList<ArrayList<Integer>> layers, HashSet<String> answers)
	{
		for (int node : layers.get(layer))
		{
			int[] queryNodes = query(node, scan);
			for (int j = 0; j < queryNodes.length; j++)
			{
				if (queryNodes[j] == 1)
				{
					if (node <= j+1)
						answers.add( Integer.toString(node) + " " + Integer.toString(j+1));
					else
						answers.add( Integer.toString(j+1) + " " + Integer.toString(node));
				}
			}
		}
	}
	
	public static int[] query(int i, Scanner scan)
	{
		System.out.println("? " + i);
		System.out.flush();
		String[] tokens = scan.nextLine().split(" ");
		int[] nodes = new int[tokens.length];
		for (int j = 0; j < tokens.length; j++)
			nodes[j] = Integer.parseInt(tokens[j]);
		return nodes;
	}
	
	public static int max(int[] arr)
	{
		int maxx = -1;
		for (int num : arr)
			if (num > maxx)
				maxx = num;
		return maxx;
	}
}