#include <bits/stdc++.h>
using namespace std;
bool chmin(int& a, int b) { return b < a ? a = b, true : false; }
bool chmax(int& a, int b) { return b > a ? a = b, true : false; }
bool chmin(long long& a, long long b) { return b < a ? a = b, true : false; }
bool chmax(long long& a, long long b) { return b > a ? a = b, true : false; }
const int inf = 1e09 + 5e3;
const long long linf = 2e18 + 5e3;
const int mod = 1e9 + 7;
const int mxn = 1e5 + 30;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<vector<long long> > val(n, vector<long long>(n, -1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int prev = 0;
      int ui = i, uj = j;
      if (val[i][j] == -1) {
        do {
          val[ui][uj] = prev;
          prev ^= 1;
          ui++, uj--;
        } while (uj >= 0 && ui < n);
      }
    }
  };
  ;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == 0 && i == j) continue;
      val[i][j] <<= i + j - 1;
    }
  };
  ;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << val[i][j] << ' ';
      assert(val[i][j] <= 1e16);
    }
    cout << '\n';
  }
  cout << endl;
  ;
  ;
  int q;
  cin >> q;
  while (q--) {
    vector<pair<int, int> > out = {{0, 0}};
    long long k;
    cin >> k;
    int curi = 0, curj = 0;
    while (curi != n - 1 || curj != n - 1) {
      long long f = k & (1ll << (curi + curj));
      if (curj < n - 1 && val[curi][curj + 1] == f) {
        out.push_back({curi, ++curj});
      } else {
        out.push_back({++curi, curj});
      }
    }
    for (auto blah : out)
      cout << blah.first + 1 << ' ' << blah.second + 1 << '\n';
    cout << endl;
    assert(out.size() == 2 * n - 1);
  }
}
