#include <bits/stdc++.h>
int a[4][4] = {8, 9, 1, 13, 3, 12, 7, 5, 0, 2, 4, 11, 6, 10, 15, 14},
    b[1005][1005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n * n / 16; i++) {
    int x = (i % (n / 4)) * 4, y = (i / (n / 4)) * 4;
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 4; k++) b[x + j][y + k] = a[j][k] + 16 * i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) printf("%d ", b[i][j]);
    printf("\n");
  }
}
