#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> ar;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << std::fixed;
  cout << std::setprecision(4);
  long long int n;
  cin >> n;
  long long int mat[n][n];
  int v = 0;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4) {
      for (int k = (0); k < (4); k++) {
        for (int l = (0); l < (4); l++) {
          mat[i + k][j + l] = v++;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << mat[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
