#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  auto num = [&](int i, int j) { return ll(i & 1) << (i + j); };
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << num(i, j) << ' ';
    }
    cout << endl;
  }
  int q;
  cin >> q;
  while (q--) {
    ll k;
    cin >> k;
    int i = 0, j = 0;
    while (!(i == n - 1 && j == n - 1)) {
      cout << i + 1 << ' ' << j + 1 << endl;
      if (i < n - 1 && bool(k & (1LL << (i + 1 + j))) == bool(num(i + 1, j)))
        ++i;
      else
        ++j;
    }
    cout << n << ' ' << n << endl;
  }
}
