#include <bits/stdc++.h>
using namespace std;
int n, a[1002][1002];
int main() {
  scanf("%d", &n);
  for (int i = 0, cnt = 0; i < n; i += 4)
    for (int j = 0; j < n; j += 4) {
      for (int x = 0; x < 4; ++x)
        for (int y = 0; y < 4; ++y) a[i + x][j + y] = cnt++;
    }
  for (int i = 0; i < n; ++i, printf("\n"))
    for (int j = 0; j < n; ++j) printf("%d ", a[i][j]);
  return 0;
}
