#include <bits/stdc++.h>
using namespace std;
const int MAX_INT = (1ll << 31) - 1;
const int INF = 2e9 + 10;
const long long inf = 9e18 + 10;
const int MO = 1e9 + 7;
const double eps = 1e-7;
const int N = 29;
long long a[N][N];
int n, q;
long long k;
struct P {
  int x, y;
};
vector<P> ans;
int ok;
void print() {
  int x = 1, y = 1;
  for (int i = (2); i <= (2 * n - 1); ++i) {
    printf("%d %d\n", x, y);
    cout.flush();
    if (k & (1ll << i)) {
      if (x % 2)
        y += 1;
      else
        x += 1;
    } else {
      if (x % 2)
        x += 1;
      else
        y += 1;
    }
  }
  printf("%d %d\n", x, y);
  cout.flush();
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i += 2) {
    int tot = i;
    for (int j = (1); j <= (n); ++j) a[i][j] = 1ll << tot, tot += 1;
  }
  for (int i = (1); i <= (n); ++i) {
    for (int j = (1); j <= (n); ++j)
      printf("%lld%c", a[i][j], j == n ? '\n' : ' ');
    cout.flush();
  }
  scanf("%d", &q);
  while (q--) {
    ans.clear();
    ok = 0;
    scanf("%lld", &k);
    print();
  }
  return 0;
}
