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 tank {

    static final FastScanner fs = new FastScanner();

    //static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int t = 1;
        while(t-- > 0) {
            run_case();
        }

        //out.close();
    }

    static void run_case() {
        int n = fs.nextInt(), mx = 0, ev = 0, od = 0;

        int[] arr = ask(1, n);

        StringBuilder ans = new StringBuilder("!\n");

        for(int i = 0;i < n;i++) {
            mx = Math.max(mx, arr[i]);
        }

        ArrayList<Integer>[] level = new ArrayList[mx + 1];
        int[] nodes = new int[n + 1];

        for (int i = 0; i <= mx; i++) {
            level[i] = new ArrayList<>();
        }

        for(int i = 0;i < n;i++) {
            level[arr[i]].add(i + 1);
            nodes[i + 1] = arr[i];
        }

        for(int i: level[1]) {
            ans.append(1 + " " + i).append("\n");
        }

        for (int i = 1; i <= mx; i++) {
            if(i % 2 == 0) {
                ev += level[i].size();
            }else {
                od += level[i].size();
            }
        }

        int[] tmp;

        if(ev >= od) {
            for (int i = 1; i <= mx; i+=2) {
                for(int j: level[i]) {
                    tmp = ask(j, n);

                    for(int k = 0;k < tmp.length;k++) {
                        if(tmp[k] == 1 && nodes[k + 1] == i + 1) {
                            ans.append(j + " " + (k + 1)).append("\n");
                        }

                        if(k != 0) {
                            if(tmp[k] == 1 && nodes[k + 1] == i - 1) {
                                ans.append(j + " " + (k + 1)).append("\n");
                            }
                        }
                    }
                }
            }
        }else {
            for (int i = 2; i <= mx; i+=2) {
                for(int j: level[i]) {
                    tmp = ask(j, n);

                    for(int k = 0;k < tmp.length;k++) {
                        if(tmp[k] == 1 && nodes[k + 1] == i + 1) {
                            ans.append(j + " " + (k + 1)).append("\n");
                        }

                        if(tmp[k] == 1 && nodes[k + 1] == i - 1) {
                            ans.append(j + " " + (k + 1)).append("\n");
                        }
                    }
                }
            }
        }

        System.out.println(ans);

    }

    static int[] ask(int x, int n) {
        System.out.println("? " + x);
        int[] ret = fs.readArray(n);
        System.out.flush();

        return ret;
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        String nextLine(){
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return "";
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}