#include <bits/stdc++.h>
using namespace std;
int pos[2][2] = {{0, 1}, {1, 0}};
void solve() {
  int n;
  cin >> n;
  long long arr[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i & 1) {
        arr[i][j] = (1ll << (i + j - 1));
        cout << arr[i][j];
      } else {
        arr[i][j] = 0;
        cout << arr[i][j];
      }
      cout << " ";
    }
    cout << "\n";
  }
  cout.flush();
  int q;
  cin >> q;
  while (q--) {
    long long sum;
    cin >> sum;
    int x = 1, y = 1;
    vector<array<int, 2>> v;
    v.push_back({x, y});
    for (int i = 0; i < 2 * n - 3; i++) {
      for (int j = 0; j < 2; j++) {
        int p = x + pos[j][0], r = y + pos[j][1];
        if (p > n || r > n) continue;
        if (((1ll << i) & sum) == arr[p - 1][r - 1]) {
          x = p, y = r;
          break;
        }
      }
      v.push_back({x, y});
    }
    v.push_back({n, n});
    for (auto [a, b] : v) {
      cout << a << " " << b << "\n";
    }
    cout.flush();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
