#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 2e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long qpow(long long x, long long n) {
  long long ans = 1;
  if (n < 0) {
    return 1;
  }
  while (n) {
    if (n & 1) {
      ans *= x;
    }
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long lowbit(long long x) { return x & (-x); }
long long N, M, K;
long long a[30][30];
void go(int& x, int& y, long long& k) {
  long long now = lowbit(k);
  if (a[x][y + 1] == now) {
    y++;
    write(x, ' ');
    write(y);
    k -= now;
  } else if (a[x + 1][y] == now) {
    x++;
    write(x, ' ');
    write(y);
    k -= now;
  } else if (!a[x][y + 1]) {
    y++;
    write(x, ' ');
    write(y);
  } else {
    x++;
    write(x, ' ');
    write(y);
  }
}
void init() {
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      a[i][j] = (i & 1 ? 0 : qpow(2, i + j));
    }
  }
}
void solve() {
  long long ans = 0;
  N = read();
  init();
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      write(a[i][j], j == N ? '\n' : ' ');
    }
  }
  fflush(stdout);
  M = read();
  while (M--) {
    K = read();
    for (int i = 0, j = 1; i + j < 2 * N;) {
      go(i, j, K);
    }
    fflush(stdout);
  }
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
