#include <bits/stdc++.h>
using namespace std;
const int Size = 1024;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 15;
int a[5][5] = {{0, 0, 0, 0, 0},
               {0, 0, 1, 2, 3},
               {0, 7, 6, 5, 4},
               {0, 8, 9, 10, 11},
               {0, 15, 14, 13, 12}};
int b[1015][1015];
int n;
void run(int k) {
  int tmp = k / 4;
  for (int i = 1; n >= i; i++) {
    for (int j = 1; n >= j; j++) {
      int x = i % 4, y = j % 4;
      if (x == 0) x = 4;
      if (y == 0) y = 4;
      b[i][j] =
          a[x][y] +
          ((i / 4 + (i % 4 != 0) - 1) * tmp + (j / 4 + (j % 4 != 0)) - 1) * 16;
    }
  }
}
int main() {
  scanf("%d", &n);
  run(n);
  for (int i = 1; n >= i; i++) {
    int tt = 0;
    for (int j = 1; n >= j; j++) {
      if (tt++ > 0) printf(" ");
      printf("%d", b[i][j]);
    }
    printf("\n");
  }
  return 0;
}
