#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 50040;
int n;
int mp[1200][1200];
int main() {
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 1; i <= n; i += 4) {
    for (int j = 1; j <= n; j += 4) {
      for (int k = i; k <= i + 3; ++k) {
        for (int l = j; l <= j + 3; ++l) {
          mp[k][l] = cnt++;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      printf("%d", mp[i][j]);
      if (j == n)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}
