#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int n, a[1005][1005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int x = 0;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4)
      for (int ii = 0; ii < 4; ii++)
        for (int jj = 0; jj < 4; jj++) a[i + ii][j + jj] = x++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
    cout << '\n';
  }
  return 0;
}
