#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  vector<vector<long long>> a(n, vector<long long>(n));
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < n; ++j) {
      if (i & 1LL) {
        long long next = (1LL << (i + j));
        a[i][j] = next;
      }
      cout << a[i][j] << ' ';
    }
    cout << '\n';
  }
  cout.flush();
  long long t;
  cin >> t;
  for (short test = 0; test < t; ++test) {
    long long res;
    cin >> res;
    short x = n - 1, y = n - 1;
    stack<pair<short, short>> ans;
    while (x > 0 || y > 0) {
      ans.push({x + 1, y + 1});
      res -= a[x][y];
      if (x > 0 && a[x - 1][y] & res)
        --x;
      else if (y > 0 && a[x][y - 1] & res)
        --y;
      else if (x > 0 && a[x - 1][y] == 0)
        --x;
      else if (y > 0 && a[x][y - 1] == 0)
        --y;
    }
    ans.push({1, 1});
    while (!ans.empty()) {
      x = ans.top().first;
      y = ans.top().second;
      ans.pop();
      cout << x << ' ' << y << '\n';
    }
  }
  cout.flush();
  getchar();
  return 0;
}
