#include <bits/stdc++.h>
using namespace std;
const int N = 27;
int n, t, q;
long long m[N][N];
int main() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      if (i == 0)
        m[i][j] = 0;
      else
        m[i][j] = (1 - m[i - 1][j + 1]);
    }
  for (int i = 1; i < N; i++)
    for (int j = 0; j < N; j++)
      if (m[i][j]) m[i][j] = (1ll << (1ll * (i + j)));
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << m[i][j] << " ";
    cout << '\n';
  }
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    pair<int, int> now = make_pair(0, 0);
    for (int q = 0; q < 2 * n - 1; q++) {
      cout << now.first + 1 << " " << now.second + 1 << '\n';
      if (now.first == n - 1 || (((0 < (k & (1ll << (q + 1ll)))) ==
                                  (0 < m[now.first][now.second + 1])) &&
                                 now.second + 1 < n))
        now.second++;
      else
        now.first++;
    }
  }
}
