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 <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 2e3 + 10;
int n, ans;
int a[N];
bool vis[N];
vector<int> dep[N], edges[N];
void dfs(int par, int chi) {
  for (auto i : edges[chi]) {
    if (i == par) continue;
    cout << chi << " " << i << "\n";
    dfs(chi, i);
  }
}
void solve(bool q) {
  cin >> n;
  cout << "? 1" << endl;
  int m = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dep[a[i]].push_back(i);
    m = max(m, a[i]);
    if (a[i] == 1) edges[1].push_back(i);
  }
  int cnt[] = {0, 0};
  for (int i = 1; i <= m; i++) {
    cnt[i % 2] += max(1, (int)dep[i].size() - 1);
    if (dep[i].size() == 1) cnt[1 - (i % 2)]++;
  }
  int wat = (int)(cnt[1] < cnt[0]);
  for (int i = 1; i <= m; i++) {
    if (i % 2 == wat || (dep[i].size() == 1)) {
      unordered_set<int> s;
      if (dep[i].size() > 1) {
        for (int j = 1; j < dep[i].size(); j++) {
          cout << "? " << dep[i][j] << endl;
          for (int h = 1; h <= n; h++) {
            int x;
            cin >> x;
            if (x == 1) {
              edges[dep[i][j]].push_back(h);
              s.insert(h);
            }
          }
        }
        for (auto x : dep[i + 1]) {
          if (s.find(x) == s.end()) edges[dep[i][0]].push_back(x);
        }
      } else {
        cout << "? " << dep[i][0] << endl;
        for (int h = 1; h <= n; h++) {
          int x;
          cin >> x;
          if (x == 1) {
            edges[dep[i][0]].push_back(h);
          }
        }
      }
    }
  }
  cout << "!\n";
  dfs(0, 1);
}
int main() {
  int t = 1, c = 0;
  while (t--) {
    c++;
    solve(c == 7902);
  }
}
