#include <bits/stdc++.h>
using namespace std;
const long long max_n = 25 + 5;
long long n, k;
vector<vector<long long> > a;
void printmat() {
  for (long long i = 2; (2 > 0 and i < n + 1) or (2 < 0 and i > n + 1); i += 2)
    for (long long j = 1; (1 > 0 and j < n + 1) or (1 < 0 and j > n + 1);
         j += 1)
      a[i][j] = (1LL) << (i + j);
  for (long long i = 1; (1 > 0 and i < n + 1) or (1 < 0 and i > n + 1);
       i += 1) {
    for (long long j = 1; (1 > 0 and j < n + 1) or (1 < 0 and j > n + 1);
         j += 1) {
      cout << a[i][j] << " ";
      cout.flush();
    }
    cout << endl;
    cout.flush();
  }
}
void printpath() {
  long long x = n, y = n;
  vector<pair<long long, long long> > path;
  while (x != 1 or y != 1) {
    path.push_back({x, y});
    k ^= a[x][y];
    if (x == 1)
      --y;
    else if (y == 1)
      --x;
    else {
      bool flag = false;
      if (k & ((1LL) << (x + y - 1))) flag = true;
      if (a[x - 1][y] == ((1LL) << (x + y - 1))) {
        if (flag)
          --x;
        else
          --y;
      } else {
        if (flag)
          --y;
        else
          --x;
      }
    }
  }
  path.push_back({1, 1});
  reverse(path.begin(), path.end());
  for (auto p : path) {
    cout << p.first << " " << p.second << endl;
    cout.flush();
  }
}
int main() {
  cin >> n;
  a.resize(n);
  a.assign(n + 1, vector<long long>(n + 1, 0));
  printmat();
  long long tc;
  cin >> tc;
  while (tc--) {
    cin >> k;
    printpath();
  }
  return 0;
}
