#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 1e18;
long long int power(long long int x, long long int y) {
  long long int ret = 1;
  for (int i = 0; i < y; i++) ret *= x;
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j % 2 == 0)
        cout << 0 << ' ';
      else
        cout << power(2, i + j - 1) << ' ';
    }
    cout << endl;
  }
  cout.flush();
  int q;
  cin >> q;
  while (q--) {
    long long int k;
    cin >> k;
    int x = 1, y = 1;
    bool f = 1;
    cout << x << ' ' << y << endl;
    for (int i = 0; i <= 2 * n - 3; i++) {
      if ((k >> i & 1) == f) {
        y++;
        f = !f;
      } else {
        x++;
      }
      cout << x << ' ' << y << endl;
    }
    cout.flush();
  }
  return 0;
}
