#include <bits/stdc++.h>
using namespace std;
template <class T>
string tostring(T x) {
  ostringstream out;
  out << x;
  return out.str();
}
long long toint(string s) {
  istringstream in(s);
  long long x;
  in >> x;
  return x;
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};
int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
const long long MAX = 10000000000000000LL;
long long genRand() {
  long long r = 1;
  for (int i = 50; i >= 0; i--) {
    if (rand() % 2) r |= 1LL << i;
  }
  return r;
}
vector<vector<long long>> gen(int n) {
  vector<vector<long long>> v(n);
  for (int i = 0; i < n; i++) {
    v[i] = vector<long long>(n);
    for (int j = 0; j < n; j++) {
      if (i % 2 == 0)
        v[i][j] = 0;
      else
        v[i][j] = 1LL << (i + j - 1);
    }
  }
  return v;
}
void solveOne() {
  int n;
  cin >> n;
  vector<vector<long long>> v = gen(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << v[i][j] << " ";
    cout << endl;
    cout.flush();
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    int x = 0, y = 0;
    long long cur = 0;
    for (int i = 0; i < 2 * n - 1; i++) {
      cout << x + 1 << " " << y + 1 << endl;
      cout.flush();
      cur += v[x][y];
      if (k & 1LL << i) {
        if (x % 2 == 0)
          x++;
        else
          y++;
      } else {
        if (x % 2 == 0)
          y++;
        else
          x++;
      }
    }
    assert(cur == k);
  }
}
int main() {
  srand(time(NULL));
  std::ios::sync_with_stdio(false);
  int T = 1;
  while (T--) {
    solveOne();
  }
  return 0;
}
