#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int T;
  {
    long long int t, n, i, j = 0, x, y, m = 0, l, d, k;
    long long int curr = 1;
    cin >> n;
    long long int arr[n][n];
    for (int d = 0; d < 2 * n; d++) {
      if (d <= n - 1) {
        i = 0;
        j = d - i;
      } else {
        j = n - 1;
        i = d - j;
      }
      for (; j >= 0 && i < n;) {
        m++;
        if (j % 2 == 0)
          arr[i][j] = curr;
        else
          arr[i][j] = 0;
        i++;
        j--;
      }
      curr *= 2;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cout << arr[i][j] << ' ';
      }
      cout << '\n';
    }
    cout.flush();
    cin >> t;
    while (t--) {
      cin >> k;
      vector<pair<long long, long long> > v;
      x = n - 1, y = n - 1;
      k -= arr[n - 1][n - 1];
      while (1) {
        if (x == 0 && y == 0) {
          v.push_back(make_pair(x, y));
          break;
        }
        if (x == 0) {
          v.push_back(make_pair(x, y));
          y--;
          k -= arr[x][y];
          continue;
        }
        if (y == 0) {
          v.push_back(make_pair(x, y));
          x--;
          k -= arr[x][y];
          continue;
        }
        if (arr[x - 1][y] > 0) {
          if (k > arr[x - 1][y]) {
            v.push_back(make_pair(x, y));
            x--;
            k -= arr[x][y];
          } else {
            v.push_back(make_pair(x, y));
            y--;
            k -= arr[x][y];
          }
        } else {
          if (k > arr[x][y - 1]) {
            v.push_back(make_pair(x, y));
            y--;
            k -= arr[x][y];
          } else {
            v.push_back(make_pair(x, y));
            x--;
            k -= arr[x][y];
          }
        }
      }
      reverse(v.begin(), v.end());
      for (int i = 0; i < (v.size()); ++i)
        cout << v[i].first + 1 << ' ' << v[i].second + 1 << '\n';
      cout << '\n';
      cout.flush();
    }
  }
}
