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