#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
const long long maxn = 30;
long long a[maxn][maxn];
int32_t main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (j & 1) {
        a[i][j] = ((long long)1 << (i + j));
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << a[i][j];
      if (j < n - 1)
        cout << ' ';
      else
        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;
    if (n == 1)
      cout << endl;
    else
      cout << ' ';
    for (long long i = 1; i < (2 * n - 1); i++) {
      if (x == n - 1) {
        y++;
      } else if (y == n - 1) {
        x++;
      } else if ((k & ((long long)1 << (x + 1 + y))) == a[x + 1][y]) {
        x++;
      } else {
        y++;
      }
      cout << x + 1 << ' ' << y + 1;
      if (x == n - 1 && y == n - 1)
        cout << endl;
      else
        cout << ' ';
    }
  }
  return false;
}
