#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX_N = 1000 + 5;
int n;
int a[MAX_N][MAX_N] = {
    {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};
int main() {
  scanf("%d", &n);
  int k = n / 4;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      if (i == 0 && j == 0) continue;
      for (int ii = 0; ii < 4; ii++) {
        for (int jj = 0; jj < 4; jj++) {
          a[i * 4 + ii][j * 4 + jj] = a[ii][jj] + 16 * (i * k + j);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d%c", a[i][j], j == n - 1 ? '\n' : ' ');
    }
  }
  return 0;
}
