#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
bool Debug = true;
ll maxn(vector<ll>& h) {
  ll ans = -1e18;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans = max(ans, (ll)h[ijkl]);
  }
  return ans;
}
ll minn(vector<ll>& h) {
  ll ans = 1e18;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans = min(ans, (ll)h[ijkl]);
  }
  return ans;
}
ll sumn(vector<ll>& h) {
  ll ans = 0;
  for (int ijkl = 0; ijkl < h.size(); ++ijkl) {
    ans += h[ijkl];
  }
  return ans;
}
ll pown(ll n, ll cnt) {
  if (cnt == 0) {
    return 1;
  }
  if (cnt == 1) {
    return n;
  }
  if (cnt % 2 == 0) {
    ll a = pown(n, cnt / 2);
    return (a * a) % ll(1e9 + 7);
  } else {
    ll a = pown(n, (cnt - 1) / 2);
    return (a * a) % ll(1e9 + 7) * n % ll(1e9 + 7);
  }
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ld dist(ld x1, ld y1, ld x2, ld y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
struct Point {
  int x, y;
  Point() : x(0), y(0) {}
  Point(int _x, int _y) : x(_x), y(_y) {}
  Point(Point a, Point b) : x(b.x - a.x), y(b.y - a.y) {}
};
string alph = "abcdefghijklmnopqrstuvwxyz";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  while (t--) {
    ll n;
    cin >> n;
    vector<vector<ll> > h(n, vector<ll>(n));
    ll k = 2;
    for (int i = 1; i < n; i += 2) {
      ll x = k;
      for (int j = 0; j < n; ++j) {
        h[i][j] = x;
        x *= 2;
      }
      k *= 4;
    }
    for (int i = 0; i < n; ++i) {
      for (auto ijkl : h[i]) cout << ijkl << " ";
      cout << "\n";
    }
    cout.flush();
    ll q;
    cin >> q;
    while (q--) {
      cin >> k;
      ll x = 0, y = 0;
      for (int i = 1; i < 2 * n; ++i) {
        cout << y + 1 << " " << x + 1 << "\n";
        if ((h[y][x] != 0 && ((k >> i) & 1) != 0) ||
            (h[y][x] == 0 && ((k >> i) & 1) == 0)) {
          ++x;
        } else {
          ++y;
        }
      }
      cout.flush();
    }
  }
  return 0;
}
