#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int a[maxn][maxn],
    c[4][4] = {{8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};
int n;
int main() {
  cin >> n;
  int b = n / 4;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      a[i][j] = (i / 4 * b + j / 4) * 16 + (c[i % 4][j % 4]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d ", a[i][j]);
    }
    puts("");
  }
}
