#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &str, vector<T> &a) {
  for (auto &i : a) {
    str << i << " ";
  }
  return str;
}
template <class T>
istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) {
    str >> i;
  }
  return str;
}
template <class T>
ostream &operator<<(ostream &str, pair<T, T> &a) {
  str << a.first << " " << a.second;
  return str;
}
template <class T>
istream &operator>>(istream &str, pair<T, T> &a) {
  str >> a.first >> a.second;
  return str;
}
void solve();
signed main() {
  srand(time(0));
  solve();
  return 0;
}
const long long MOD = 1e9 + 7, MAXN = 1e6 + 10, BASE = 31, INF = 1e18 + 10;
void solve() {
  long long n;
  cin >> n;
  vector<long long> p(51);
  p[0] = 1;
  for (long long i = 1; i <= 50; ++i) {
    p[i] = p[i - 1] * 2;
  }
  vector<vector<long long>> a(n + 1, vector<long long>(n + 1));
  for (long long i = 2; i <= n; i += 2) {
    for (long long j = 1; j <= n; ++j) {
      a[i][j] = p[i + j - 2];
    }
  }
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  long long q;
  cin >> q;
  for (long long _ = 0; _ < q; ++_) {
    long long k;
    cin >> k;
    vector<pair<long long, long long>> ans;
    long long i = 1, j = 1;
    ans.push_back({i, j});
    k /= 2;
    while (i < n || j < n) {
      if (i % 2 == 1) {
        if (k % 2 == 0) {
          j++;
        } else {
          i++;
        }
        ans.push_back({i, j});
        k /= 2;
      } else {
        if (k % 2 == 0) {
          i++;
        } else {
          j++;
        }
        ans.push_back({i, j});
        k /= 2;
      }
    }
    for (auto it : ans) {
      cout << it << endl;
    }
    cout << endl;
  }
}
