#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 25;
int n;
ll a[maxn][maxn];
signed main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j && (i == 0 || i == n - 1)) {
        cout << a[i][j] << " ";
        continue;
      }
      if (j % 2 == 0) {
        cout << a[i][j] << " ";
        continue;
      }
      a[i][j] = (((long long)1) << (i + j));
      cout << a[i][j] << " ";
    }
    cout << endl;
    fflush(stdout);
  }
  int q;
  cin >> q;
  while (q--) {
    ll curr;
    cin >> curr;
    int i = 0, j = 0;
    cout << i + 1 << " " << j + 1 << endl;
    fflush(stdout);
    for (int ii = 0; ii < 2 * n - 2; ++ii) {
      if (i == n - 1) {
        ++j;
        cout << i + 1 << " " << j + 1 << endl;
        fflush(stdout);
      } else if (j == n - 1) {
        ++i;
        cout << i + 1 << " " << j + 1 << endl;
        fflush(stdout);
      } else {
        if (curr == 0) {
          if (a[i + 1][j] == 0) {
            ++i;
            cout << i + 1 << " " << j + 1 << endl;
            fflush(stdout);
          } else {
            ++j;
            cout << i + 1 << " " << j + 1 << endl;
            fflush(stdout);
          }
        } else {
          ll help = curr - ((curr - 1) & curr);
          if (help == a[i + 1][j] || help == a[i][j + 1]) {
            curr -= help;
            if (a[i + 1][j] != 0) {
              ++i;
              cout << i + 1 << " " << j + 1 << endl;
              fflush(stdout);
            } else {
              ++j;
              cout << i + 1 << " " << j + 1 << endl;
              fflush(stdout);
            }
          } else {
            if (a[i + 1][j] == 0) {
              ++i;
              cout << i + 1 << " " << j + 1 << endl;
              fflush(stdout);
            } else {
              ++j;
              cout << i + 1 << " " << j + 1 << endl;
              fflush(stdout);
            }
          }
        }
      }
    }
  }
}
