#include <bits/stdc++.h>
using namespace std;
const int maxn = 25 + 20;
long long a[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i % 2 == 0 && (i + j > 0)) a[i][j] = (1LL << (i + j - 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j];
      if (j + 1 < n) cout << " ";
    }
    cout << endl;
  }
  for (int i = 0; i < maxn; i++) a[n][i] = a[i][n] = (1LL << 53);
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    int x = 0, y = 0;
    cout << 1 << " " << 1 << endl;
    for (int i = 0; i < 2 * n - 2; i++) {
      if (a[x + 1][y]) {
        if ((a[x + 1][y] & k))
          x++;
        else
          y++;
      } else {
        if ((a[x][y + 1] & k))
          y++;
        else
          x++;
      }
      cout << x + 1 << " " << y + 1 << endl;
    }
  }
}
