#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y / 2;
    if (y != 0) x = (x * x);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long q, t, n, i, j, k, ans, var, temp, c, flag, I;
  cin >> n;
  long long a[n + 5][n + 5];
  var = flag = 0;
  for (i = 0; i < n; i++) {
    I = i;
    for (j = 0; I >= 0; j++, I--) {
      if (flag)
        a[I][j] = power(2, var);
      else
        a[I][j] = 0;
      flag = flag ^ 1;
    }
    var++;
  }
  for (i = 1; i < n; i++) {
    flag = 0;
    I = i;
    for (j = n - 1; I < n; j--, I++) {
      if (flag)
        a[j][I] = power(2, var);
      else
        a[j][I] = 0;
      flag = flag ^ 1;
    }
    var++;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) cout << a[i][j] << "  ";
    cout << endl;
  }
  cin >> q;
  while (q--) {
    cin >> k;
    c = i = j = 0;
    cout << "1 1" << endl;
    k /= 2;
    c++;
    while (i != n - 1 || j != n - 1) {
      if (k & 1) {
        if (i + 1 < n && a[i + 1][j] != 0) {
          i++;
          cout << i + 1 << " " << j + 1 << endl;
        } else {
          j++;
          cout << i + 1 << " " << j + 1 << endl;
        }
      } else {
        if (i + 1 < n && a[i + 1][j] == 0) {
          i++;
          cout << i + 1 << " " << j + 1 << endl;
        } else {
          j++;
          cout << i + 1 << " " << j + 1 << endl;
        }
      }
      c++;
      k /= 2;
    }
  }
  return 0;
}
