#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> v(n);
  int mat[4][4] = {
      {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};
  int ans[n][n];
  for (int i = 0; i < n * n; i++) {
    int x = i / n;
    v[x].push_back(i);
  }
  int count = 0;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4) {
      for (int k = i; k < i + 4; k++) {
        for (int l = j; l < j + 4; l++) {
          ans[k][l] = count++;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == 0)
        cout << ans[i][j];
      else
        cout << " " << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}
