#include <bits/stdc++.h>
using namespace std;
void ETA() {
  long long int n;
  cin >> n;
  long long int matrix[n + 1][n + 1];
  for (long long int i = 1; i <= n; i++) {
    if (i % 2)
      for (long long int j = 1; j <= n; j++) matrix[i][j] = (1LL << (i + j));
    else
      for (long long int j = 1; j <= n; j++) matrix[i][j] = 0;
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) cout << matrix[i][j] << " ";
    cout << endl;
  }
  long long int q, val;
  cin >> q;
  while (q--) {
    cin >> val;
    string binary = bitset<50>(val).to_string();
    reverse(binary.begin(), binary.end());
    long long int x = 1, y = 1;
    cout << "1 1" << endl;
    while (x + y < 2 * n) {
      if (x == n)
        y++;
      else if (y == n)
        x++;
      else if (x % 2) {
        if (binary[x + y + 1] == '1')
          y++;
        else
          x++;
      } else {
        if (binary[x + y + 1] == '1')
          x++;
        else
          y++;
      }
      cout << x << " " << y << endl;
    }
    cout << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    ETA();
  }
  return 0;
}
