#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
}
int main() {
  fastio();
  long long n;
  cin >> n;
  long long mat[n][n];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i % 2)
        mat[i][j] = (1LL << (i + j));
      else
        mat[i][j] = 0;
      cout << mat[i][j] << " ";
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long x = 0, y = 0;
    while (x < n && y < n) {
      cout << (x + 1) << " " << (y + 1) << endl;
      k >>= 1LL;
      if (k & 1LL) {
        if (!mat[x][y])
          ++x;
        else
          ++y;
      } else {
        if (!mat[x][y])
          ++y;
        else
          ++x;
      }
    }
  }
  return 0;
}
