#include <bits/stdc++.h>
using namespace std;
long long a[102][102];
long long bb[102][102];
void tpel(int a, int b) {
  cout << a << " " << b << endl;
  cout.flush();
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      long long ord = (i + j) - 2ll;
      long long bt = (i % 2ll);
      a[i][j] = (bt << ord);
      bb[i][j] = bt;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << a[i][j] << " ";
    }
    cout << endl;
    cout.flush();
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    long long k;
    cin >> k;
    int x = 1;
    int u = 1;
    tpel(x, u);
    long long ord = 1;
    for (int f = 0; f < (2 * (n - 1)); ++f) {
      if (x == n)
        ++u;
      else if (u == n)
        ++x;
      else {
        long long curbt = ((k >> ord) & 1ll);
        if (curbt == bb[x + 1][u])
          ++x;
        else
          ++u;
      }
      tpel(x, u);
      ++ord;
    }
  }
}
int main() {
  int t;
  t = 1;
  while (t) {
    --t;
    solve();
  }
  return 0;
}
