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;
queue<int> q;
bool visited[2005];
string s = "!";
void solve(int i, vector<int>& prev) {
  vector<int> d;
  int p = -1;
  int g = 0, k;
  map<int, vector<int>> avail;
  visited[i] = 1;
  avail.erase(i);
  cout << "? " << i + 1 << endl;
  cout.flush();
  for (int j = 0, x; j < n; ++j) {
    cin >> x;
    d.push_back(x);
    if (x == 1 && prev[j] == 1) {
      p = j;
      ++g;
      k = j;
      visited[j] = 1;
      s.append("\n" + to_string(j + 1) + " " + to_string(i + 1));
    } else if (j == i || visited[j] || prev[j] < d[j]) {
    } else if (d[j] == 2 && prev[j] == 2) {
      visited[j] = 1;
      s.append("\n" + to_string(j + 1) + " " + to_string(p + 1));
    } else if (x == 1) {
      visited[j] = 1;
      s.append("\n" + to_string(j + 1) + " " + to_string(i + 1));
    } else {
      avail[x].push_back(j);
    }
  }
  if (g == 1 && avail.size()) {
    int y = 2, z = 0;
    auto it = avail.begin();
    for (; it != avail.end(); ++it) {
      if (avail[y].size() == 1) {
        ++z;
        s.append("\n" + to_string(k + 1) + " " + to_string(it->second[0] + 1));
        k = it->second[0];
        visited[it->second[0]] = 1;
      }
    }
    for (; it != avail.end(); ++it) {
      for (auto h : it->second) {
        d[h] -= z;
      }
    }
  }
  for (int j = 0; j < n; ++j) {
    if (!visited[j] && d[j] == 2) solve(j, d);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<int> d;
  cin >> n;
  cout << "? 1" << endl;
  visited[0] = 1;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    d.push_back(x);
    if (x == 1) {
      visited[i] = 1;
      s.append("\n1 " + to_string(i + 1));
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!visited[i] && d[i] == 2) solve(i, d);
  }
  cout << s << endl;
  return 0;
}
