#include <bits/stdc++.h>
using namespace std;
bool ok(const pair<int, int>& p, const vector<vector<long long>>& a, int d,
        long long k) {
  int x = p.first;
  int y = p.second;
  int n = a.size();
  if (x >= n || y >= n) {
    return false;
  }
  long long value = a[x][y];
  bool haveValue = value > 0;
  bool havePath = (k >> d) & 1LL;
  return haveValue == havePath;
}
vector<pair<int, int>> solve(const vector<vector<long long>>& a, long long k) {
  int x = 0;
  int y = 0;
  int n = a.size();
  vector<pair<int, int>> answer;
  for (int i = 0; i < 2 * n - 2; i++) {
    vector<pair<int, int>> candidates = {{x + 1, y}, {x, y + 1}};
    pair<int, int> cur;
    for (auto cand : candidates) {
      if (ok(cand, a, i + 1, k)) {
        cur = cand;
      }
    }
    answer.push_back({x + 1, y + 1});
    x = cur.first;
    y = cur.second;
  }
  answer.push_back({x + 1, y + 1});
  return answer;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<long long>> a(n, vector<long long>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int status = j % 2;
      int diag = i + j;
      if (status) {
        a[i][j] = 1LL << diag;
      }
    }
  }
  for (auto v : a) {
    for (long long value : v) {
      cout << value << " ";
    }
    cout << "\n";
  }
  cout.flush();
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long k;
    cin >> k;
    vector<pair<int, int>> answer = solve(a, k);
    for (auto p : answer) {
      cout << p.first << " " << p.second << "\n";
    }
    cout.flush();
  }
  return 0;
}
