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

public class Agad {
    public static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int n = scanner.nextInt();
        System.out.println("? 1");
        int[] d = new int[n + 1];
        for (int i = 1; i <= n; i++) d[i] = scanner.nextInt() + 1;
        StringBuilder builder = new StringBuilder();
        dfs(1, 0, n, d, new boolean[n + 1], builder);
        System.out.println("!");
        System.out.println(builder.toString());
    }
    public static void dfs(int u, int p, int n, int[] d, boolean[] vi, StringBuilder s) {
        if (p > 0) {
            s.append(u + " " + p + "\n");
        }
        int c = 0, f = 0;;
        for (int i = 1; i <= n; i++) {
            if (!vi[i]) {
                if (d[i] == 1) {
                    c++;
                } else if (d[i] > 1) {
                    f++;
                }
            }
        }
        vi[u] = true;
        if (f == 0) return;
        int[] m = new int[n + 1];
        if (c == 1) {
            for (int i = 1; i <= n; i++) m[i] = d[i] - 1;
        } else {
            System.out.println("? " + u);
            for (int i = 1; i <= n; i++) m[i] = scanner.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            if (!vi[i] && m[i] == 1 && d[i] == 2) {
                dfs(i, u, n, m, vi, s);
            }
        }
    }
}