#include <bits/stdc++.h>
using namespace std;
long long mnp[2000005];
void sieve() {
  mnp[0] = mnp[1] = 1;
  for (long long i = 2; i < 2000005; i++) mnp[i] = i;
  for (long long i = 2; i < 2000005; i += 2) mnp[i] = 2;
  for (long long i = 3; i * i <= 2000005; i += 2) {
    if (mnp[i] == i) {
      for (long long j = i; j < 2000005; j += (i + i)) {
        if (mnp[j] == j) mnp[j] = i;
      }
    }
  }
}
pair<long long, long long> fact(long long x) {
  long long odd = 1, even = 0;
  while (x > 1) {
    long long p = mnp[x];
    long long cnt = 0;
    while (x > 1 && x % p == 0) {
      x = x / p;
      cnt++;
    }
    if (p == 2) {
      even += cnt;
    } else {
      odd *= (cnt + 1);
    }
  }
  return {even * odd, odd};
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n;
  cin >> n;
  long long cnt = 0;
  long long mat[n + 1][n + 1];
  for (long long i = 1; i <= n; i += 4) {
    for (long long j = 1; j <= n; j += 4) {
      for (long long k = i; k < i + 4; k++) {
        for (long long l = j; l < j + 4; l++) {
          mat[k][l] = cnt++;
        }
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) cout << mat[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
