#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 5;
const long long MOD = 1e9 + 7;
long long a[26][26];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j % 2) a[i][j] = 1LL << (i + j);
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  int q;
  cin >> q;
  while (q--) {
    long long first;
    cin >> first;
    int posx = 0;
    int posy = 0;
    cout << 1 << " " << 1 << endl;
    while (posx != n - 1 or posy != n - 1) {
      if (posx == n - 1)
        posy++;
      else if (posy == n - 1)
        posx++;
      else {
        if (posy % 2 == 0) {
          if (first & a[posx][posy + 1]) {
            posy++;
          } else {
            posx++;
          }
        } else {
          if (first & a[posx + 1][posy]) {
            posx++;
          } else {
            posy++;
          }
        }
      }
      cout << posx + 1 << " " << posy + 1 << endl;
    }
  }
  return 0;
}
