#include <bits/stdc++.h>
int main() {
  int n, q, x, y, rem;
  long long a[26][26], k;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0)
        a[i][j] = ((long long)1 << (i + j));
      else
        a[i][j] = 0;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      printf("%lld%c", a[i][j], j < n - 1 ? ' ' : '\n');
      fflush(stdout);
    }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%lld", &k);
    x = 0, y = 0;
    rem = k % 2;
    for (int j = 1; j < 2 * n; j++) {
      printf("%d %d\n", x + 1, y + 1);
      fflush(stdout);
      k /= 2;
      rem = k % 2;
      if (x == n - 1)
        y++;
      else if (y == n - 1)
        x++;
      else {
        if (rem == 0) {
          if (a[x + 1][y] == 0)
            x++;
          else
            y++;
        } else {
          if (a[x + 1][y] == 0)
            y++;
          else
            x++;
        }
      }
    }
  }
  return 0;
}
