#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<vector<long long int>> mat(n, vector<long long int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i & 1) mat[i][j] = 1ll << (i + j);
      cout << mat[i][j] << " ";
    }
    cout << endl;
  }
  long long int q, a;
  cin >> q;
  while (q--) {
    cin >> a;
    cout << "1 1" << endl;
    int x = 0, y = 0;
    while (x != n - 1 || y != n - 1) {
      if (x == n - 1) {
        y++;
      } else if (y == n - 1) {
        x++;
      } else if (mat[x][y]) {
        if (mat[x][y + 1] & a)
          y++;
        else
          x++;
      } else {
        if (mat[x + 1][y] & a)
          x++;
        else
          y++;
      }
      cout << x + 1 << " " << y + 1 << endl;
    }
  }
}
int main() {
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
