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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void eraseDups(vector<int>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
int strToInt(string& a) {
  stringstream x(a);
  int b;
  x >> b;
  return b;
}
int bitCnt(int a) {
  bitset<64> b(a);
  return b.count();
}
int bitCnt(string a) {
  bitset<64> b(a);
  return b.count();
}
vector<int> readVI(int n) {
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  return a;
}
vector<vector<int> > readVVI(int n, int m) {
  vector<vector<int> > a(n, vector<int>(m));
  for (int i = 0; i < n; i++) a[i] = readVI(m);
  return a;
}
vector<long long> readVLL(long long n) {
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  return a;
}
vector<vector<long long> > readVVLL(long long n, long long m) {
  vector<vector<long long> > a(n, vector<long long>(m));
  for (int i = 0; i < n; i++) a[i] = readVLL(m);
  return a;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void print(vector<int>& a) {
  for (auto el : a) {
    cout << el << ' ';
  }
  cout << '\n';
}
void print(vector<pair<int, int> >& a) {
  for (auto el : a) {
    cout << el.first << ',' << el.second << ' ';
  }
  cout << '\n';
}
void print(vector<int>& a, int n) {
  int cnt = 0;
  for (auto el : a) {
    if (cnt++ == n) break;
    cout << el << ' ';
  }
  cout << '\n';
}
void print(vector<vector<int> >& a) {
  for (auto el : a) {
    print(el);
  }
}
const int MOD = 1e9 + 7;
const int MOD1 = 998244353;
const int INF = 2e9;
const long long INFF = INT64_MAX;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int moveX[] = {-1, 0, 1, 0};
const int moveY[] = {0, 1, 0, -1};
set<pair<int, int> > edges;
void ans() {
  cout << "!\n";
  cout << edges.size() << '\n';
  for (auto el : edges) {
    cout << el.first << ' ' << el.second << '\n';
  }
}
const int N = 1005;
vector<bool> vis(N, 0);
int n;
vector<int> ask(int a) {
  cout << "? " << a << '\n';
  vector<int> tmp = readVI(n);
  vis[a] = 1;
  vector<int> cnt(n + 5, 0), val(n + 5, 0), visVal(n + 5, 0);
  for (int i = 0; i < n; i++) {
    int el = tmp[i];
    cnt[el]++, val[el] = i + 1;
    if (vis[i + 1]) visVal[tmp[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (tmp[i] == 0) continue;
    if (cnt[tmp[i] - 1] == 1) {
      int aa = i + 1, b = val[tmp[i] - 1];
      if (aa > b) swap(aa, b);
      edges.insert({aa, b});
    }
    if (cnt[tmp[i] + 1] == visVal[tmp[i] + 1] &&
        cnt[tmp[i] - 1] == visVal[tmp[i] - 1]) {
      vis[i + 1] = 1;
    }
  }
  return tmp;
}
void go() {
  cin >> n;
  vector<int> initial = ask(1);
  set<pair<int, int> > bfs;
  for (int i = 1; i <= n; i++) {
    bfs.insert({initial[i], i});
  }
  while (!bfs.empty() && edges.size() < n - 1) {
    auto it = bfs.begin();
    bfs.erase(it);
    int a, b;
    tie(a, b) = *it;
    if (vis[b]) continue;
    vis[b] = 1;
    vector<int> cur = ask(b);
    int dist = initial[b - 1];
    vector<pair<int, int> > tmp;
    for (int i = 1; i <= n; i++) {
      if (cur[i - 1] + initial[i - 1] == dist) {
        tmp.push_back({initial[i - 1], i});
      }
    }
    sort(tmp.begin(), tmp.end());
    for (int i = 1; i < tmp.size(); i++) {
      int aa = tmp[i - 1].second, bb = tmp[i].second;
      if (aa > bb) swap(aa, bb);
      edges.insert({aa, bb});
    }
  }
  ans();
}
signed main() {
  int T = 1;
  while (T--) go();
  return 0;
}
