#include <bits/stdc++.h>
using namespace std;
const int MAX = 30;
long long arr[MAX][MAX], vis[MAX][MAX], bit[MAX * 3];
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long now = 1ll;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (vis[i][j]) continue;
      now *= 2ll;
      bit[i + j] = now;
      int i2 = i, j2 = j;
      bool flag = 0;
      while (i2 < n && j2 >= 0) {
        vis[i2][j2] = 1;
        flag = !flag;
        if (flag) arr[i2][j2] = now;
        i2++, j2--;
      }
    }
  }
  arr[0][0] = arr[n - 1][n - 1] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cout << arr[i][j] << " ";
    cout << "\n";
  }
  cout << endl;
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    int x = 0, y = 0;
    cout << 1 << " " << 1 << "\n";
    for (int i = 1; i <= n * 2 - 2; ++i) {
      if (x == n - 1) {
        ++y;
        cout << x + 1 << " " << y + 1 << "\n";
      } else if (y == n - 1) {
        ++x;
        cout << x + 1 << " " << y + 1 << "\n";
      } else {
        long long a = (k & bit[x + y + 1]);
        if (a == arr[x + 1][y])
          ++x;
        else
          ++y;
        cout << x + 1 << " " << y + 1 << "\n";
      }
    }
    cout << endl;
  }
  return 0;
}
