#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 2;
int arr[N][N];
inline void solve() {
  int n, cnt(0);
  cin >> n;
  for (int i = 1; i <= n; i += 4) {
    for (int j = 1; j <= n; j += 4) {
      for (int k = 0; k < 4; ++k) {
        arr[i][k + j] = cnt++;
      }
      for (int k = 0; k < 4; ++k) {
        arr[i + 1][k + j] = cnt++;
      }
      for (int k = 0; k < 4; ++k) {
        arr[i + 2][k + j] = cnt++;
      }
      for (int k = 0; k < 4; ++k) {
        arr[i + 3][k + j] = cnt++;
      }
    }
  }
  for (int i = 1; i <= n; i += 1) {
    for (int j = 1; j <= n; j += 1) {
      cout << arr[i][j] << " \n"[j == n];
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
