#include <bits/stdc++.h>
using namespace std;
int arr[1010][1010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n / 4; i++) {
    for (int j = 0; j < n / 4; j++) {
      int base = 16 * i * (n / 4) + j * 16;
      for (int k = i * 4; k < i * 4 + 4; k++) {
        if (k % 2 == 0) {
          for (int l = j * 4; l < j * 4 + 4; l++) {
            arr[k][l] = base;
            base++;
          }
        } else {
          for (int l = j * 4 + 3; l >= j * 4; l--) {
            arr[k][l] = base;
            base++;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << arr[i][j] << ' ';
    }
    cout << '\n';
  }
}
