#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  while (!isdigit(c)) f ^= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
}
using namespace std;
long long a[30][30];
int main() {
  long long n, q, val, x, y, op;
  cin >> n;
  long long r = 0;
  for (int i = 1; i <= n; i++) {
    long long w = 1 << r;
    if (i % 2 == 1) {
      for (int j = 1; j <= n; j++) {
        a[i][j] = w;
        w *= 2;
      }
    } else {
      for (int j = 1; j <= n; j++) {
        a[i][j] = 0;
      }
    }
    r++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  fflush(stdout);
  cin >> q;
  while (q--) {
    cin >> val;
    x = 1;
    y = 1;
    cout << x << " " << y << endl;
    val /= 2;
    while (val >= 0) {
      op = val % 2;
      if (op == 1) {
        if (a[x][y] != 0) {
          y++;
        } else {
          x++;
        }
        cout << x << " " << y << endl;
        if (x == n && y == n) {
          break;
        }
      } else {
        if (a[x][y] != 0) {
          x++;
        } else {
          y++;
        }
        cout << x << " " << y << endl;
        if (x == n && y == n) {
          break;
        }
      }
      val /= 2;
    }
    fflush(stdout);
  }
  return 0;
}
