#include <bits/stdc++.h>
using namespace std;
const long long N = 25;
long long v[N][N];
void solve() {
  long long n;
  cin >> n;
  long long x, y;
  long long t = 1;
  for (long long i = 0; i < n; i++) {
    if (i % 2 == 0) {
      for (long long j = 0; j < n; j++) {
        v[i][j] = 0;
      }
    } else {
      long long tt = t;
      t <<= 1;
      for (long long j = 0; j < n; j++) {
        v[i][j] = tt;
        tt <<= 1;
      }
      t <<= 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << v[i][j] << " ";
    }
    cout << "\n";
  }
  fflush(stdout);
  long long q;
  cin >> q;
  while (q--) {
    long long ans = 0;
    cin >> ans;
    long long x = 1, y = 1;
    cout << "1 1\n";
    for (long long i = 0; i < (n * 2 - 2); i++) {
      if (ans & 1) {
        if (y % 2)
          y++;
        else
          x++;
      } else {
        if (y % 2)
          x++;
        else
          y++;
      }
      cout << y << " " << x << "\n";
      ans >>= 1;
    }
    fflush(stdout);
  }
}
signed main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
