#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
inline void solve(int x, int y, int g) {
  for (int i = x; i < x + 4; ++i)
    for (int j = y; j < y + 4; ++j) {
      a[i][j] = g;
      ++g;
    }
}
int main() {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 1; i <= n; i += 4)
    for (int j = 1; j <= n; j += 4) {
      solve(i, j, cnt);
      cnt += 16;
    }
  for (int i = 1; i <= n; ++i, cout << "\n") {
    int res1 = 0, res2 = 0;
    for (int j = 1; j <= n; ++j) {
      cout << a[i][j] << " ";
    }
  }
}
