#include <bits/stdc++.h>
using namespace std;
long long saveori[33][33];
long long n;
inline long long qpow(long long a, long long n) {
  long long res = 1;
  long long base = a;
  while (n) {
    if (n & 1) res = res * base;
    base = base * base;
    n >>= 1;
  }
  return res;
}
vector<long long> v;
void dfs(long long hang, long long lie) {
  printf("%lld %lld\n", hang, lie);
  if (lie + 1 <= n && saveori[hang][lie + 1] == v.back()) {
    v.pop_back();
    dfs(hang, lie + 1);
    return;
  } else if (hang + 1 <= n && saveori[hang + 1][lie] == v.back()) {
    v.pop_back();
    dfs(hang + 1, lie);
    return;
  }
  if (hang + 1 <= n && saveori[hang + 1][lie] == 0)
    dfs(hang + 1, lie);
  else if (lie + 1 <= n)
    dfs(hang, lie + 1);
  return;
}
void solve() {
  cin >> n;
  long long base = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) saveori[i][j] = qpow(2, i + j);
  }
  for (long long i = 1; i <= n; i += 2) {
    for (long long j = 1; j <= n; j++) saveori[i][j] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      printf("%lld ", saveori[i][j]);
    }
    puts("");
  }
  puts("");
  cout.flush();
  fflush(stdout);
  long long q;
  scanf("%lld", &q);
  while (q--) {
    long long k;
    scanf("%lld", &k);
    long long base = 1;
    while (k) {
      if (k & 1) {
        v.push_back(base);
      }
      base *= 2;
      k >>= 1;
    }
    reverse(v.begin(), v.end());
    dfs(1, 1);
    puts("");
    cout.flush();
    fflush(stdout);
    v.clear();
  }
}
signed main() { solve(); }
