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 int N = 1e6 + 1067, md = 1e9 + 7;
int n;
int par[N];
vector<int> ask(int x) {
  cout << "? " << x << endl;
  vector<int> result;
  result.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> result[i];
  }
  return result;
}
void solve(int x, bool hasAsked, vector<int> step1, vector<int> step2) {
  vector<int> s1, s2, s3;
  if (!hasAsked) {
    vector<int> ans = ask(x);
    for (int i = 1; i <= n; i++)
      if (par[i] == -1) {
        if (ans[i] == 1) s1.push_back(i);
        if (ans[i] == 2) s2.push_back(i);
        if (ans[i] == 3) s3.push_back(i);
      } else {
        if (par[x] == -1 && ans[i] == 1) par[x] = i;
      }
  } else {
    s1 = step1;
    s2 = step2;
  }
  if (s1.size() == 0) return;
  for (auto y : s1) {
    par[y] = x;
  }
  if (s1.size() == 1 && !hasAsked) {
    solve(s1[0], true, s2, s3);
  } else {
    if (s1.size() <= s2.size()) {
      for (auto y : s1) {
        solve(y, false, s1, s2);
      }
    } else {
      for (auto y : s2) {
        solve(y, false, s1, s2);
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) par[i] = -1;
  par[1] = 0;
  solve(1, false, vector<int>(), vector<int>());
  cout << "!" << endl;
  for (int i = 2; i <= n; i++) cout << i << " " << par[i] << endl;
}
