#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &t) {
  int f = 0, c = getchar();
  t = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  if (f) t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
int ans[1005][1005];
int main() {
  int n;
  read(n);
  int sum = 0;
  for (int i = 1; i <= n / 4; i++) {
    for (int j = 1; j <= n / 4; j++) {
      ans[i * 4][j * 4] = 8 + sum;
      ans[i * 4][j * 4 + 1] = 9 + sum;
      ans[i * 4][j * 4 + 2] = 1 + sum;
      ans[i * 4][j * 4 + 3] = 13 + sum;
      ans[i * 4 + 1][j * 4] = 3 + sum;
      ans[i * 4 + 1][j * 4 + 1] = 12 + sum;
      ans[i * 4 + 1][j * 4 + 2] = 7 + sum;
      ans[i * 4 + 1][j * 4 + 3] = 5 + sum;
      ans[i * 4 + 2][j * 4] = 0 + sum;
      ans[i * 4 + 2][j * 4 + 1] = 2 + sum;
      ans[i * 4 + 2][j * 4 + 2] = 4 + sum;
      ans[i * 4 + 2][j * 4 + 3] = 11 + sum;
      ans[i * 4 + 3][j * 4] = 6 + sum;
      ans[i * 4 + 3][j * 4 + 1] = 10 + sum;
      ans[i * 4 + 3][j * 4 + 2] = 15 + sum;
      ans[i * 4 + 3][j * 4 + 3] = 14 + sum;
      sum += 16;
    }
  }
  for (int i = 4; i <= n + 3; i++) {
    for (int j = 4; j <= n + 3; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}
