#include <bits/stdc++.h>
template <class T>
inline T qmin(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T qmax(T a, T b) {
  return a > b ? a : b;
}
const double eps = 1e-9;
const double PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int mod = (int)998244353;
const int maxn = (int)1e5 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int M[1005][1005];
int main() {
  int n;
  scanf("%d", &n);
  int num = 0;
  for (int i = 1; i <= n; i += 4) {
    for (int j = 1; j <= n; j += 4) {
      for (int k = 0; k < 4; k++) {
        for (int l = 0; l < 4; l++) {
          M[i + k][j + l] = num;
          num++;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%d ", M[i][j]);
    printf("\n");
  }
  return 0;
}
