#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<vector<long long>> v(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i & 1) {
        v[i][j] = (1LL << (i + j));
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << v[i][j] << ' ';
    }
    cout << "\n";
  }
  42;
  long long q;
  cin >> q;
  while (q--) {
    long long sum;
    cin >> sum;
    long long i = 1, j = 1;
    cout << i << ' ' << j << "\n";
    while (i < n and j < n) {
      if (i & 1 ^ 1) {
        if (sum & (1LL << (i + j - 1))) {
          j += 1;
        } else {
          i += 1;
        }
      } else {
        if (sum & (1LL << (i + j - 1))) {
          i += 1;
        } else {
          j += 1;
        }
      }
      cout << i << ' ' << j << "\n";
    }
    while (j < n) {
      j += 1;
      cout << i << ' ' << j << "\n";
    }
    while (i < n) {
      i += 1;
      cout << i << ' ' << j << "\n";
    }
  }
}
int32_t main() { solve(); }
