#include <bits/stdc++.h>
using namespace std;
const char newl = '\n';
void DEBUGLOCAL() { cerr << ")" << newl; }
template <class A, class... B>
void DEBUGLOCAL(A argc, B... argv) {
  cerr << argc;
  if (sizeof...(argv)) cerr << ", ";
  DEBUGLOCAL(argv...);
}
int ts;
int n, q;
vector<vector<long long>> a;
void construct() {
  a = vector<vector<long long>>(n, vector<long long>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i % 2)
        a[i][j] = 0;
      else
        a[i][j] = 1LL << (i + j);
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  cout.flush();
}
void path(long long sum) {
  int i = 0, j = 0;
  while (i + j < 2 * n - 2) {
    cout << i + 1 << ' ' << j + 1 << newl;
    long long tmp = sum & (1LL << (i + j + 1));
    if (tmp) {
      if (i % 2)
        ++i;
      else
        ++j;
    } else {
      if (i % 2)
        ++j;
      else
        ++i;
    }
  }
  cout << n << ' ' << n << newl;
  cout.flush();
}
void solve() {
  cin >> n;
  construct();
  cin >> q;
  while (q--) {
    long long tmp;
    cin >> tmp;
    path(tmp);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
