#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<long long>> g(n, vector<long long>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (!(i == 0 && j == 0 || i == n - 1 && j == n - 1)) {
        int s = i + j - 1;
        if (j & 1) g[i][j] = 1LL << s;
      }
      cout << g[i][j] << ' ';
    }
    cout << endl;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    long long k;
    cin >> k;
    int x = 0, y = 0;
    cout << x + 1 << ' ' << y + 1 << endl;
    while (x != n - 1 || y != n - 1) {
      if (x == n - 1)
        y += 1;
      else if (y == n - 1)
        x += 1;
      else {
        int s = x + y;
        if ((g[x + 1][y] >> s & 1) == (k >> s & 1))
          x += 1;
        else
          y += 1;
      }
      cout << x + 1 << ' ' << y + 1 << endl;
    }
  }
}
