#include <bits/stdc++.h>
using namespace std;
template <class A = long long int>
void Out(vector<A> a) {
  for (long long int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class A = long long int>
void In(vector<A> &a, long long int N) {
  A cur;
  for (long long int i = 0; i < N; i++) {
    cin >> cur;
    a.push_back(cur);
  }
}
template <class T = long long int>
vector<pair<T, long long int> > streak(vector<T> a) {
  vector<pair<T, long long int> > ans;
  if (a.size() == 0) {
    return ans;
  }
  long long int curstr = 0LL;
  T cur = a[0];
  for (long long int i = 0; i < a.size(); i++) {
    if (cur == a[i]) {
      curstr++;
    } else {
      ans.push_back(make_pair(cur, curstr));
      cur = a[i];
      curstr = 1LL;
    }
  }
  ans.push_back(make_pair(cur, curstr));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int N;
  cin >> N;
  for (long long int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      for (long long int j = 0; j < N; j++) {
        cout << 0 << " ";
      }
    } else {
      for (long long int j = 0; j < N; j++) {
        cout << (1LL << (i + j)) << " ";
      }
    }
    cout << endl;
  }
  long long int Q;
  cin >> Q;
  for (long long int q = 0; q < Q; q++) {
    long long int K;
    cin >> K;
    vector<long long int> d;
    for (long long int i = 0; i < 2LL * N - 1LL; i++) {
      long long int cur = K & (1LL << i);
      if (cur > 0LL) {
        cur = 1LL;
      }
      d.push_back(cur);
    }
    vector<pair<long long int, long long int> > s = streak(d);
    vector<long long int> inter;
    for (long long int i = 0; i < s.size(); i++) {
      inter.push_back(s[i].second);
    }
    pair<long long int, long long int> cur = make_pair(1, 1);
    for (long long int i = 0; i < N; i++) {
      for (long long int j = 0; j < inter[i]; j++) {
        cout << cur.first << " " << cur.second << endl;
        cur.second++;
      }
      cur.second--;
      cur.first++;
    }
  }
  return 0;
}
