#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
long long n, now[4][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
inline long long find(long long x, long long y) {
  return (x / 4) * (n / 4) + y / 4 + 1;
}
signed main() {
  n = read();
  for (register long long i = 0; i <= n - 1; i++) {
    for (register long long j = 0; j <= n - 1; j++) {
      long long at = find(i, j);
      cout << (at - 1) * 16 + now[i % 4][j % 4] << " ";
    }
    puts("");
  }
  return 0;
}
