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 i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int number_of_tests = 1;
  while (number_of_tests--) {
    int n;
    std::cin >> n;
    if (n == 2) {
      std::cout << "!\n1 2" << std::endl;
      continue;
    }
    std::vector<std::pair<int, int>> edges;
    auto ask = [&](int r) {
      std::cout << "? " << r + 1 << std::endl;
      std::vector<int> d(n, 0);
      for (int i = 0; i < n; ++i) {
        std::cin >> d[i];
      }
      return d;
    };
    int d1, d2;
    std::vector<int> ddist1, ddist2;
    int diamlen;
    std::vector<int> vis(n, 0);
    bool found = false;
    {
      auto d = ask(0);
      if (n <= 4) {
        vis[0] = 1;
        d1 = -1;
        for (int i = 0; i < n; ++i) {
          if (d[i] == 1) edges.push_back({i, 0});
          vis[i] = 1;
          if (d1 == -1 || d[i] > d[d1]) d1 = i;
        }
        if (n == 4 && d[d1] == 3) {
          auto D = ask(d1);
          for (int i = 0; i < n; ++i) {
            if (D[i] == 1) edges.push_back({d1, i});
          }
          for (int u = 0; u < 4; ++u) {
            for (int v = u + 1; v < 4; ++v) {
              if (u != 0 && u != d1) edges.push_back({u, v});
            }
          }
        } else if (n == 4 && d[d1] == 2) {
          auto D = ask(d1);
          int M = -1;
          for (int i = 0; i < n; ++i) {
            if (D[i] == 1) {
              edges.push_back({d1, i});
              M = i;
            }
          }
          for (int i = 0; i < 4; ++i)
            if (i != 0 && i != d1 && i != M) {
              edges.push_back({i, M});
            }
        } else if (n == 3 && d[d1] == 2) {
          auto D = ask(d1);
          for (int i = 0; i < n; ++i) {
            if (D[i] == 1) edges.push_back({d1, i});
          }
        }
      } else {
        d1 = -1;
        for (int i = 0; i < n; ++i)
          if (d1 == -1 || d[i] > d[d1]) d1 = i;
        d = ask(d1);
        d2 = -1;
        for (int i = 0; i < n; ++i)
          if (d2 == -1 || d[i] > d[d2]) d2 = i;
        diamlen = d[d2];
        ddist1 = d;
        ddist2 = ask(d2);
      }
    }
    if (n > 4) {
      std::vector<std::pair<int, int>> ti;
      int left = n;
      for (int i = 0; i < n; ++i) {
        if (ddist1[i] + ddist2[i] == diamlen) {
          ti.push_back({ddist1[i], i});
          vis[i] = 1;
          --left;
        }
      }
      std::sort(ti.begin(), ti.end());
      for (int i = 0; i < (int)ti.size() - 1; ++i) {
        edges.push_back({ti[i].second, ti[i + 1].second});
      }
      std::queue<int> Q;
      for (int i = 0; i < n; ++i) {
        if (ddist1[i] + ddist2[i] == diamlen + 2) {
          edges.push_back({ti[ddist1[i] - 1].second, i});
          Q.push(i);
          --left;
          vis[i] = 1;
        }
      }
      while (!Q.empty() && left) {
        int u = Q.front();
        Q.pop();
        auto d = ask(u);
        for (int i = 0; i < n; ++i) {
          if (d[i] == 1 && !vis[i]) {
            edges.push_back({u, i});
            vis[i] = 1;
            --left;
            Q.push(i);
          }
        }
      }
    }
    std::cout << "!\n";
    for (auto [u, v] : edges) {
      std::cout << u + 1 << ' ' << v + 1 << '\n';
    }
    std::cout << std::endl;
  }
  return 0;
}
