#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
long long modexp(long long a, long long b, long long m) {
  long long r = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    b = b / 2;
    a = (a * a) % m;
  }
  return r % m;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<vector<long long>> grid(n, vector<long long>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i - j + n) & 2LL) grid[i][j] = (1LL << (i + j));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << grid[i][j] << ' ';
    }
    cout << '\n';
  }
  cout << flush;
  int nbQuery;
  cin >> nbQuery;
  for (int iQuery = 0; iQuery < nbQuery; ++iQuery) {
    long long sum;
    cin >> sum;
    cout << "1 1\n";
    int row = 0, col = 0;
    for (int diag = 0; diag < 2 * n - 2; ++diag) {
      long long should = sum & (1LL << (diag + 1));
      if (row + 1 < n && grid[row + 1][col] == should)
        ++row;
      else
        ++col;
      cout << row + 1 << " " << col + 1 << '\n';
    }
    cout << '\n' << flush;
  }
}
