#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << '\n'; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
long long int func(long long int i, long long int j) { return (53 - i - j); }
int main() {
  int TESTS = 1;
  while (TESTS--) {
    long long int n;
    cin >> n;
    long long int arr[n + 1][n + 1];
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j <= n; j++) {
        long long int val = 1ll << func(i, j);
        if (i % 2 == 0) val = 0;
        arr[i][j] = val;
      }
    }
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j <= n; j++) {
        cout << arr[i][j] << " ";
      }
      cout << '\n';
      fflush(stdout);
    }
    long long int q;
    cin >> q;
    while (q--) {
      long long int x;
      cin >> x;
      vector<pair<long long int, long long int> > v;
      v.push_back({1, 1});
      pair<long long int, long long int> cur = v[0];
      for (long long int i = 2; i <= 2 * n - 1; i++) {
        if (cur.first == n) {
          cur.second++;
          v.push_back(cur);
          continue;
        }
        if (cur.second == n) {
          cur.first++;
          v.push_back(cur);
          continue;
        }
        long long int b = func(i + 1, 0);
        if ((x >> b) & 1ll) {
          if (arr[cur.first + 1][cur.second] != 0) {
            cur.first++;
          } else {
            cur.second++;
          }
        } else {
          if (arr[cur.first + 1][cur.second] == 0) {
            cur.first++;
          } else {
            cur.second++;
          }
        }
        v.push_back(cur);
      }
      for (auto it : v) {
        cout << it.first << " " << it.second << '\n';
        fflush(stdout);
      }
    }
  }
  return 0;
}
