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>
int n, d[2005];
bool u[2005];
void ask(int i) {
  printf("? %d\n", i + 1);
  fflush(stdout);
  for (int i = 0; i < n; ++i) scanf("%d", d + i);
}
int main() {
  scanf("%d", &n);
  std::vector<int> cur;
  cur.push_back(0);
  u[0] = true;
  bool step2 = false;
  std::vector<std::pair<int, int> > edge;
  while (true) {
    std::vector<int> next[2];
    for (int j = 0; j < (int)cur.size(); ++j) {
      ask(cur[j]);
      for (int k = 0; k < n; ++k) {
        if (d[k] == 1 && u[k] && step2)
          edge.push_back(std::make_pair(k, cur[j]));
        if (d[k] == 1 && !u[k]) {
          u[k] = true;
          edge.push_back(std::make_pair(k, cur[j]));
          next[0].push_back(k);
        }
        if (d[k] == 2 && !u[k]) next[1].push_back(k);
      }
    }
    if (next[1].empty()) break;
    if (next[0].size() < next[1].size()) {
      step2 = false;
      cur = next[0];
    } else {
      for (int i = 0; i < (int)next[1].size(); ++i) u[next[1][i]] = true;
      step2 = true;
      cur = next[1];
    }
  }
  printf("!\n");
  for (int i = 0; i < n - 1; ++i)
    printf("%d %d\n", edge[i].first + 1, edge[i].second + 1);
  return 0;
}
