#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxN = 1e3 + 5;
int n, arr[maxN][maxN];
void fill_sq(int x, int y, int k) {
  for (int i = (0); i <= ((4) - 1); ++i) {
    for (int j = (0); j <= ((4) - 1); ++j) {
      arr[x + i][y + j] = k++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4) {
      fill_sq(i, j, cnt * 16);
      cnt++;
    }
  }
  for (int i = (0); i <= ((n)-1); ++i) {
    for (int j = (0); j <= ((n)-1); ++j) {
      cout << arr[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
