#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int count = n / 4;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4) {
      for (int k = i; k < i + 4; k++) {
        for (int m = j; m < j + 4; m++) {
          a[k][m] = cnt++;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
