#include <bits/stdc++.h>
using namespace std;
int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(long long &x) { return scanf("%lld", &x); }
int read(long long &x, long long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) {
  int r = scanf("%s", buff);
  s = buff;
  return r;
}
int main() {
  int N;
  read(N);
  vector<vector<long long> > V(N, vector<long long>(N));
  long long b = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j <= i; ++j) {
      V[i - j][j] = (j % 2 == 0 ? b : 0);
    }
    b <<= 1;
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j <= (N - i - 1); ++j) {
      V[N - 1 - j][i + j] = (j % 2 == 0 ? b : 0);
    }
    b <<= 1;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cout << V[i][j] << " ";
    }
    cout << endl;
  }
  int Q;
  read(Q);
  for (int i = 0; i < Q; ++i) {
    long long K;
    read(K);
    pair<int, int> p(0, 0);
    cout << p.first + 1 << " " << p.second + 1 << endl;
    for (int i = 0; i < (N + N - 2); ++i) {
      long long b = (K >> i) & 1;
      if (b) {
        if (p.first + 1 < N && V[p.first + 1][p.second] > 0) {
          p.first++;
        } else {
          p.second++;
        }
      } else {
        if (p.first + 1 == N || V[p.first + 1][p.second] > 0) {
          p.second++;
        } else {
          p.first++;
        }
      }
      cout << p.first + 1 << " " << p.second + 1 << endl;
    }
  }
}
