#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i, j, k, x, y, m;
  cin >> n;
  x = 0;
  long long int A[n][n];
  for (i = 0; i < n; i += 4) {
    for (j = 0; j < n; j += 4) {
      for (k = 0; k < 4; k++) {
        for (m = 0; m < 4; m++) {
          A[i + k][j + m] = x;
          x += 1;
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
