#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int M = 75;
long long f[75];
long long a[26][26];
int n;
vector<int> trans(vector<int> ans) {
  for (int i = int(0); i < int(((int)(ans).size()) - 1); ++i) {
    int t = i;
    while (t > 0 && ans[t] == 0 && ans[t + 1] == 0) {
      ans[t] = ans[t + 1] = 1;
      ans[t - 1] = 0;
      t -= 2;
    }
  }
  return ans;
}
vector<pair<int, int> > res(long long sum) {
  vector<int> ans;
  for (int i = int(3 * n - 2) - 1; i >= int(0); --i) {
    if (sum >= f[i]) {
      sum -= f[i];
      ans.push_back(1);
    } else {
      ans.push_back(0);
    }
  }
  ans = trans(ans);
  reverse((ans).begin(), (ans).end());
  pair<int, int> st(0, 0);
  int t = 0;
  vector<pair<int, int> > tek;
  tek.push_back(st);
  while (t + 1 < ((int)(ans).size())) {
    if (ans[t + 1] == 1) {
      st.first++;
      t++;
    } else {
      st.second++;
      t += 2;
    }
    tek.push_back(st);
  }
  return tek;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  f[0] = 1;
  f[1] = 2;
  for (int i = int(2); i < int(M); ++i) {
    f[i] = f[i - 1] + f[i - 2];
  }
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    for (int j = int(0); j < int(n); ++j) {
      a[i][j] = f[i + 2 * j];
      cout << a[i][j] << ' ';
    }
    cout << endl;
  }
  int q;
  cin >> q;
  for (int t = int(0); t < int(q); ++t) {
    long long sum;
    cin >> sum;
    vector<pair<int, int> > ans = res(sum);
    for (int i = int(0); i < int(((int)(ans).size())); ++i) {
      cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
    }
  }
  return 0;
}
