#include <bits/stdc++.h>
const long double PI = acos(-1);
using namespace std;
inline long long mod(long long n, long long m = 1000000007) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long exp(long long n, long long k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  long long ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
void solution() {
  long long n;
  cin >> n;
  long long mat[n][n];
  long long st = 1;
  for (long long i = 0; i < n; i++) {
    long long cur = st;
    for (long long j = 0; j < n; j++) {
      if (i % 2)
        mat[i][j] = 0;
      else
        mat[i][j] = cur;
      cur *= 2LL;
    }
    st *= 2LL;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << mat[i][j] << " ";
    }
    cout << '\n';
  }
  cout.flush();
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    vector<pair<long long, long long> > path;
    k -= mat[n - 1][n - 1];
    long long x = n - 1, y = n - 1;
    path.push_back(pair<long long, long long>(x, y));
    while (x != 0 || y != 0) {
      if (x - 1 < 0) {
        y--;
        k -= mat[x][y];
      } else if (y - 1 < 0) {
        x--;
        k -= mat[x][y];
      } else {
        if (mat[x - 1][y] > mat[x][y - 1]) {
          if (k >= mat[x - 1][y]) {
            x--;
            k -= mat[x][y];
          } else {
            y--;
            k -= mat[x][y];
          }
        } else {
          if (k >= mat[x][y - 1]) {
            y--;
            k -= mat[x][y];
          } else {
            x--;
            k -= mat[x][y];
          }
        }
      }
      path.push_back(pair<long long, long long>(x, y));
    }
    reverse(path.begin(), path.end());
    for (pair<long long, long long> p : path)
      cout << p.first + 1 << " " << p.second + 1 << '\n';
    cout.flush();
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  long long t = 1;
  while (t--) solution();
}
