#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long a[n][n];
  long long g = n / 4;
  for (long long i = 0; i < g; i++) {
    for (long long j = 0; j < g; j++) {
      for (long long k = 0; k < 4; k++) {
        for (long long l = 0; l < 4; l++) {
          a[k + i * 4][l + 4 * j] = k * 4 + l + j * 16 + i * 4 * n;
        }
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
