#include <bits/stdc++.h>
using namespace std;
int64_t seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline int64_t rnd(int64_t l = 0, int64_t r = numeric_limits<int64_t>::max()) {
  return uniform_int_distribution<int64_t>(l, r)(rng);
}
template <typename T, typename G>
ostream& operator<<(ostream& out, const pair<T, G>& a) {
  return out << "( " << a.first << ", " << a.second << ")";
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[ ";
  for (const auto& i : a) out << i << ", ";
  return out << "]" << endl;
}
template <typename T>
ostream& operator<<(ostream& out, const set<T>& a) {
  out << "{ ";
  for (const auto& i : a) out << i << ", ";
  return out << "}" << endl;
}
template <typename T, typename G>
ostream& operator<<(ostream& out, const map<T, G>& a) {
  out << "< ";
  for (const auto& i : a) out << i << ", ";
  return out << ">" << endl;
}
template <typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
                   ostream&>::type
operator<<(ostream& out, T (&a)[N]) {
  out << "[ ";
  for (const auto& i : a) out << i << ", ";
  return out << "]" << endl;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << (H) << ' ';
  debug_out(T...);
}
static char GLOBAL_STATE = 'R';
class Icout {
  char STATE = 'O';

 public:
  template <typename T>
  Icout& operator<<(T& a) {
    if (GLOBAL_STATE != STATE) {
      std::cerr << endl << "  sol: ";
      GLOBAL_STATE = STATE;
    }
    std::cerr << a;
    std::cout << a;
    return *this;
  }
  void tie(int64_t a) { std::cout.tie(0); }
  Icout& operator<<(std::ostream& (*p)(std::ostream&)) {
    std::cerr << *p;
    std::cout << *p;
    return *this;
  }
} customcout;
class Icin {
  char STATE = 'I';

 public:
  template <typename T>
  Icin& operator>>(T& a) {
    if (GLOBAL_STATE != STATE) {
      std::cerr << endl << "judge: ";
      GLOBAL_STATE = STATE;
    }
    std::cin >> a;
    std::cerr << a << ' ';
    return *this;
  }
  void tie(int64_t a) { std::cout.tie(0); }
} customcin;
const int64_t offset = 25;
int64_t a[26][26];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t n = 25;
  cin >> n;
  for (int64_t i = 0; i < n; ++i) {
    for (int64_t j = 0; j < n; ++j) {
      a[i][j] = ((1ll << (i + j - 1)) * (i & 1ll));
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  int64_t T;
  cin >> T;
  while (T--) {
    int64_t sum;
    cin >> sum;
    vector<pair<int64_t, int64_t> > ans;
    int64_t i = 0, j = 0;
    while (i < n && j < n) {
      sum -= a[i][j];
      ans.push_back({i + 1, j + 1});
      if (i == n - 1) {
        j++;
      } else if (j == n - 1) {
        i++;
      } else {
        if (sum & (1ll << (i + j))) {
          if (a[i][j + 1] < a[i + 1][j])
            i++;
          else
            j++;
        } else {
          if (a[i][j + 1] < a[i + 1][j])
            j++;
          else
            i++;
        }
      }
    }
    for (int64_t i = 0; i < ans.size(); ++i)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
