#include <bits/stdc++.h>
using namespace std;
int arr[30][30];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == 1)
        arr[i][j] = j - 1;
      else if ((j & 1))
        arr[i][j] = j + i - 1;
      if (arr[i][j] == 0)
        printf("0 ");
      else
        printf("%lld ", 1ll << (arr[i][j] - 1));
    }
    printf("\n");
    fflush(stdout);
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    long long v;
    scanf("%lld", &v);
    int x = 1, y = 1;
    int state = 0;
    for (int i = 0; i < 2 * n - 1; ++i) {
      printf("%d %d\n", x, y);
      fflush(stdout);
      if (state == 0) {
        if (v >> i & 1)
          y++;
        else {
          x++, i++;
          if (y & 1) {
            state = 1;
          } else {
            state = 2;
          }
        }
      } else if (state == 1) {
        if (v >> i & 1)
          x++;
        else {
          y++;
          state = 2;
        }
      } else {
        if ((v >> i & 1) == 0)
          x++;
        else {
          y++;
          state = 1;
        }
      }
    }
    printf("%d %d\n", x, y);
    fflush(stdout);
  }
  return 0;
}
