#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<vector<int>> ta(n, vector<int>(n));
  int ind = 0;
  for (int i = 0; i < n / 4; i++) {
    for (int j = 0; j < n / 4; j++) {
      for (int ii = 0; ii < 4; ii++) {
        for (int jj = 0; jj < 4; jj++) {
          ta[i * 4 + ii][j * 4 + jj] = 16 * ind + (ii * 4 + jj);
        }
      }
      ind++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << ta[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
