#include <bits/stdc++.h>
using namespace std;
void beginn() {
  long long n, a, b, c, second = 0;
  cin >> n;
  long long A[n][n];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) A[i][j] = 0;
  for (long long j = n - 2; j >= 0; j--)
    for (long long i = 1; i < n; i++) {
      A[i][j] = second + 1;
      second = 0;
      for (long long ii = 0; ii <= i; ii++) second += A[ii][j];
      for (long long ii = i; ii < n; ii++) second += A[ii][j + 1];
      for (long long jj = j + 2; jj < n; jj++) second += A[n - 1][jj];
      if (i == n - 1)
        for (long long jj = j; jj < n; jj++) second -= A[1][jj];
      else {
        for (long long ii = 0; ii <= i; ii++) second -= A[ii][j];
        for (long long jj = j + 1; jj < n; jj++) second -= A[i + 1][jj];
      }
    }
  long long S[n][n];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) {
      second = 0;
      for (long long ii = i; ii < n; ii++) second += A[ii][j];
      for (long long jj = j + 1; jj < n; jj++) second += A[n - 1][jj];
      S[i][j] = second;
    }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) cout << A[i][j] << " ";
    cout << endl;
  }
  cout.flush();
  long long q;
  cin >> q;
  while (q--) {
    long long w;
    cin >> w;
    long long x = 0, y = 0;
    while (x != n - 1 && y != n - 1) {
      cout << x + 1 << " " << y + 1 << endl;
      w -= A[x][y];
      if (S[x][y + 1] >= w)
        y++;
      else
        x++;
    }
    while (x != n - 1 || y != n - 1) {
      cout << x + 1 << " " << y + 1 << endl;
      if (x == n - 1)
        y++;
      else
        x++;
    }
    cout << n << " " << n << endl;
    cout.flush();
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) beginn();
  return 0;
}
