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;
long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; }
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
long long qpow(long long a, long long b) {
  long long t = 1;
  while (b != 0) {
    if (b & 1) t = (t * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return t;
}
template <typename T>
void re(T& a) {
  for (auto& t : a) cin >> t;
}
template <typename T>
void pr(T& a) {
  for (auto& t : a) cout << t << " ";
  cout << endl;
}
int n;
void ask(int x) {
  cout << "? " << x << endl;
  fflush(stdout);
}
const int N = 2020;
int a[N][N];
vector<pair<int, int> > ans;
queue<pair<int, int> > q;
bool vis[N];
void solve() {
  cin >> n;
  q.push({1, 0});
  while (q.size()) {
    int x = q.front().first;
    int fa = q.front().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    ask(x);
    for (int i = 1; i <= n; ++i) cin >> a[x][i];
    for (int i = 1; i <= n; ++i) {
      if (a[x][i] == 1) {
        vis[i] = 1;
        ans.push_back({x, i});
      }
    }
    for (int i = 1; i <= n; ++i) {
      if (a[x][i] == 1 && a[fa][i] == 1) {
        int y = i;
        for (int j = 1; j <= n; ++j) {
          if (a[x][j] == 2 && a[fa][j] == 2) {
            vis[j] = 1;
            ans.push_back({y, j});
          }
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && a[x][i] == 2) q.push({i, x});
    }
  }
  cout << "!" << endl;
  fflush(stdout);
  for (auto& t : ans) {
    cout << t.first << " " << t.second << endl;
    fflush(stdout);
  }
}
signed main() {
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
