#include <bits/stdc++.h>
using namespace std;
const long long maxm = 35;
long long a[maxm][maxm];
long long cal(long long i, long long j) { return i + j; }
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (i % 2) {
        cout << 0 << ' ';
      } else {
        long long t = cal(i, j);
        cout << (1LL << t) << ' ';
      }
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long sum = 0;
    cin >> sum;
    long long x = 1, y = 1;
    for (long long i = 1; i <= (n - 1) * 2; i++) {
      cout << x << ' ' << y << endl;
      if (x % 2 == 0) {
        if (y + 1 <= n) {
          long long t = cal(x, y + 1);
          if (sum & (1LL << t)) {
            y++;
          } else {
            x++;
          }
        } else {
          x++;
        }
      } else {
        if (x + 1 <= n) {
          long long t = cal(x + 1, y);
          if (sum & (1LL << t)) {
            x++;
          } else {
            y++;
          }
        } else {
          y++;
        }
      }
    }
    cout << x << ' ' << y << endl;
  }
  return 0;
}
