#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
#pragma GCC target("avx,avx2")
const int MAX_NUM = 1e9 + 33;
void solve();
int n;
signed main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x = 1 << i;
    for (int q = 0; q < n; q++) {
      if ((q + n + 1) % 2) {
        cout << x << " ";
        x <<= 2;
      } else
        cout << "0 ";
    }
    cout << endl;
  }
  long long t;
  cin >> t;
  while (t--) solve();
}
bool nThBit(long long a, int i) { return (a >> i) % 2; }
void pr(int i, int q) { cout << i + 1 << " " << q + 1 << endl; }
int whatBit(int ri, int rq) { return ri + 2 * (rq / 2 + 1) - 2; }
void solve() {
  long long a;
  cin >> a;
  deque<pair<int, int>> pairs(n * 2 - 1);
  int index = pairs.size() - 1;
  auto f = [&](int x, int y) { pairs[index--] = {x, y}; };
  int i = n - 1, q = n - 1;
  f(i, q);
  while (q != 0 && i != 0) {
    for (int j = i; j >= 0; j--) {
      int b = whatBit(j, q - 1);
      if (nThBit(a, b)) {
        while (i > j) f(--i, q);
        f(i, --q);
        if (q == 0) break;
        while (i > 0 && nThBit(a, whatBit(i - 1, q))) {
          f(--i, q);
        }
        f(i, --q);
        break;
      }
    }
  }
  while (q != 0) f(i, --q);
  while (i != 0) f(--i, q);
  for (auto bb : pairs) {
    pr(bb.first, bb.second);
  }
}
