#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
mt19937 rnd(51);
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> v(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i % 2 == 1) {
        v[i][j] = (1LL << (i + j));
      }
      cout << v[i][j] << " ";
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long sum, i = n - 1, j = n - 1;
    cin >> sum;
    vector<pair<long long, long long>> ans;
    while (i > 0 && j > 0) {
      ans.push_back({i, j});
      sum -= v[i][j];
      if (v[i - 1][j] > v[i][j - 1]) {
        if (sum >= v[i - 1][j]) {
          i--;
        } else {
          j--;
        }
      } else {
        if (sum >= v[i][j - 1]) {
          j--;
        } else {
          i--;
        }
      }
    }
    if (i == 0) {
      while (j >= 0) {
        ans.push_back({i, j--});
      }
    }
    if (j == 0) {
      while (i >= 0) {
        ans.push_back({i--, j});
      }
    }
    reverse(ans.begin(), ans.end());
    for (auto to : ans) {
      cout << to.first + 1 << " " << to.second + 1 << endl;
    }
  }
  return 0;
}
