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;
int n;
vector<int> depth;
vector<int> getDistances(int u) {
  cout << "? " << u << endl;
  vector<int> d(n + 1);
  for (int i = 1; i <= n; i++) cin >> d[i];
  return d;
}
void updateParents(int leaf, vector<int> &parent) {
  vector<int> d = getDistances(leaf);
  vector<pair<int, int>> sortedD;
  for (int u = 1; u <= n; u++) {
    sortedD.push_back({d[u], u});
  }
  sort(sortedD.begin(), sortedD.end());
  int curLayer = depth[leaf] - 1;
  int cur = leaf;
  vector<int> chain = {leaf};
  for (auto p : sortedD) {
    int u = p.second;
    if (depth[u] == curLayer) {
      if (parent[cur] != -1) break;
      chain.push_back(u);
      parent[cur] = u;
      cur = u;
      curLayer--;
    }
  }
  for (int u = 1; u <= n; u++) {
    if (d[u] == 1 && depth[u] > depth[leaf]) {
      parent[u] = leaf;
    }
  }
}
int main() {
  cin >> n;
  depth = getDistances(1);
  vector<int> parent(n + 1, -1);
  for (int i = 2; i <= n; i++) {
    if (depth[i] == 1) {
      parent[i] = 1;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (parent[i] == -1) {
      updateParents(i, parent);
    }
  }
  cout << "!" << endl;
  for (int i = 2; i <= n; i++) {
    assert(parent[i] != -1);
    cout << parent[i] << " " << i << endl;
  }
  return 0;
}
