#include <bits/stdc++.h>
using namespace std;
void FREOPEN() {}
inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = (int)2000, inf = (int)2e9, MOD = (int)1e9 + 7, alph = 26;
char CH[N];
const long long INF = (long long)1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
const int dp[] = {8, 9, 1, 13, 3, 12, 7, 5, 0, 2, 4, 11, 6, 10, 15, 14};
int a[N][N];
int main() {
  FREOPEN();
  int n;
  cin >> n;
  int num = 0;
  for (int bi = 0; bi < n; bi += 4) {
    for (int bj = 0; bj < n; bj += 4) {
      for (int i = bi; i < bi + 4; i++) {
        for (int j = bj; j < bj + 4; j++) {
          int p = (i - bi) * 4 + (j - bj);
          a[i][j] = (dp[p] ^ num);
        }
      }
      num += 16;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) printf("%d ", a[i][j]);
    printf("\n");
  }
  return 0;
}
