#include <bits/stdc++.h>
long long CMB[50][50];
void computeCMB() {
  for (long long i = 0; i < 50; ++i) {
    CMB[i][0] = 1;
    for (long long j = 1; j <= i; ++j) {
      CMB[i][j] = CMB[i - 1][j - 1] + CMB[i - 1][j];
    }
  }
}
long long n;
long long pathsFrom(long long i, long long j) {
  long long steps = (n - i) + (n - j);
  long long v = (n - i);
  return CMB[steps][v];
}
long long V[25 + 1][25 + 1];
long long maxPath(long long x, long long y) {
  long long sum = 0;
  while (x < n) sum += V[x][y], ++x;
  while (y < n) sum += V[x][y], ++y;
  return sum;
}
long long minCost(long long X, long long Y) {
  long long sum = 0;
  long long x = 1, y = 1;
  while (y < Y) sum += V[x][y], ++y;
  while (x < X) sum += V[x][y], ++x;
  return sum;
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  computeCMB();
  std::cin >> n;
  for (long long j = n - 1, v = 0; j >= 1; --j) {
    for (long long i = 2; i <= n; ++i) {
      v += pathsFrom(i, j + 1);
      V[i][j] = v - maxPath(i, j + 1) - minCost(i, j);
    }
  }
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      std::cout << V[i][j] << ' ';
    }
    std::cout << std::endl;
    std::cout.flush();
  }
  long long q;
  std::cin >> q;
  for (long long i = 0, k; i < q; ++i) {
    std::cin >> k;
    long long x = 1, y = 1;
    long long weight = 0;
    for (long long ln = 0; ln < 2 * n - 1; ++ln) {
      std::cout << x << ' ' << y << std::endl;
      std::cout.flush();
      long long v = maxPath(x, y + 1);
      if (y == n || weight + v < k) {
        ++x;
      } else {
        ++y;
      }
      weight += V[x][y];
    }
  }
  return 0;
}
