#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<vector<long long>> g(n, vector<long long>(n));
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < n; ++j) {
      if (not((i + 1) & 1ll)) g[i][j] = (1LL << (i + j));
      cout << g[i][j] << ' ';
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    cout << 1 << ' ' << 1 << endl;
    long long r = 0, c = 0;
    for (long long i = 1; i < 2 * n - 1; ++i) {
      long long x = k & (1ll << i);
      if (r + 1 < n and g[r + 1][c] == x)
        r++;
      else
        c++;
      cout << r + 1 << ' ' << c + 1 << endl;
    }
  }
  return 0;
}
