#include <bits/stdc++.h>
using namespace std;
long long v, k, a[30][30], n, q, i, j, x, y;
int main() {
  cin >> n;
  for (i = 1; i <= 2 * n; i++)
    for (j = 1; j < i; j++)
      if (i - j <= n && j <= n) {
        k = i - j;
        if (j % 2 == 0) a[j][k] = 0;
        if (j % 2 == 1) a[j][k] = 1ll << (i - 2);
      }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) cout << a[i][j] << " ";
    cout << endl;
  }
  cin >> q;
  while (q--) {
    cin >> v;
    cout << "1 1" << endl;
    v = v / 2;
    x = 1;
    y = 1;
    for (i = 1; i <= 2 * n - 2; i++) {
      if (v % 2 == 0) {
        if (x % 2 == 0) {
          y++;
          cout << x << " " << y << endl;
        }
        if (x % 2 == 1) {
          x++;
          cout << x << " " << y << endl;
        }
      }
      if (v % 2 == 1) {
        if (x % 2 == 1) {
          y++;
          cout << x << " " << y << endl;
        }
        if (x % 2 == 0) {
          x++;
          cout << x << " " << y << endl;
        }
      }
      v = v / 2;
    }
  }
}
