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

#include <array>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n;
int a[2010];
int b[2010];
bool solved[2010];
vector<pair<int, int>> result;

void solve(int v, int depth) {
    cout << "? " << v + 1 << endl;

    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    int parent = 0;

    for (int i = 0; i < n; i++) {
        if (b[i] == 1 && a[i] == depth - 1) {
            parent = i;
            break;
        }
    }

    solved[v] = true;
    result.emplace_back(parent, v);

    for (int i = 0; i < n; i++) {
        if (b[i] == 2 && a[i] == depth) {
            solved[i] = true;
            result.emplace_back(parent, i);
        }
    }

    for (int i = 0; i < n; i++) {
        if (b[i] == 1 && a[i] == depth + 1) {
            solved[i] = true;
            result.emplace_back(v, i);
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    FILE* input_txt = freopen("input.txt", "r", stdin);
    FILE* output_txt = freopen("output.txt", "w", stdout);
    assert(input_txt != nullptr && output_txt != nullptr);
#else
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
#endif

    cin >> n;

    cout << "? " << 1 << endl;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    solved[0] = true;

    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            solved[i] = true;
            result.emplace_back(0, i);
        }
    }

    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[j] == i && !solved[j]) {
                solve(j, i);
            }
        }
    }

    cout << "!" << endl;
    for (int i = 0; i < result.size(); i++) {
        cout << result[i].first + 1 << " " << result[i].second + 1 << endl;
    }

    return 0;
}
