#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7, N = 30;
long long a[N][N];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i == 0 && j == 0) continue;
      if (i == n - 1 && j == n - 1) continue;
      long long x = 1LL << (i + j - 1);
      if (i % 2 == 0) a[i][j] = x;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long x = 0, y = 0;
    cout << x + 1 << " " << y + 1 << endl;
    for (long long i = 0; i < 2 * n - 2; i++) {
      if (x == n - 1)
        y++;
      else if (y == n - 1)
        x++;
      else {
        if ((a[x + 1][y] && (k & a[x + 1][y]) == a[x + 1][y]) ||
            (a[x][y + 1] && (k & a[x][y + 1]) != a[x][y + 1]))
          x++;
        else
          y++;
      }
      cout << x + 1 << " " << y + 1 << endl;
    }
  }
}
