#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int> > grid(n, vector<int>(n));
  int cur = 0;
  for (int i = 0; i < n / 4; ++i) {
    for (int j = 0; j < n / 4; ++j) {
      for (int u = 0; u < 4; ++u) {
        for (int v = 0; v < 4; ++v) {
          grid[i * 4 + u][j * 4 + v] = cur++;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cout << grid[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
