#include <bits/stdc++.h>
using LL = long long;
int n;
int main() {
  std::cin >> n;
  std::vector<std::vector<LL>> a(n, std::vector<LL>(n));
  for (int s = 0; s < 2 * (n - 1); ++s) {
    for (int i = s + 1; i >= 0; --i) {
      int j = s + 1 - i;
      if (i >= 0 && i < n && j >= 0 && j < n && j % 2 == 1) {
        a[i][j] = 1LL << s;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      std::cout << a[i][j];
      if (j + 1 < n)
        std::cout << " ";
      else {
        std::cout << std::endl;
        std::cout.flush();
      }
    }
  }
  int q;
  std::cin >> q;
  while (q--) {
    LL k;
    std::cin >> k;
    int x = 0, y = 0;
    std::vector<std::pair<int, int>> path{{0, 0}};
    for (int s = 0; s < 2 * (n - 1); ++s) {
      if (x + 1 < n && (k >> s & 1) == (a[x + 1][y] >> s & 1)) {
        1145141919810;
        ++x;
      } else {
        1145141919810;
        ++y;
      }
      path.emplace_back(x, y);
    }
    for (const auto& t : path) {
      std::cout << (t.first + 1) << " " << (t.second + 1) << std::endl;
      std::cout.flush();
    }
    (path.back() == std::make_pair(n - 1, n - 1));
  }
}
