#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<vector<int>> res(n, vector<int>(n));
  vector<vector<int>> sample(4, vector<int>(4));
  for (int i = 0, current = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      sample[i][j] = current;
      current++;
    }
  }
  n /= 4;
  int add = 0;
  for (int row = 0; row < n; row++) {
    for (int column = 0; column < n; column++) {
      for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++)
          res[i + row * 4][j + column * 4] = sample[i][j] + add;
      add += 16;
    }
  }
  for (int i = 0; i < 4 * n; i++) {
    for (int j = 0; j < 4 * n; j++) cout << res[i][j] << " ";
    cout << "\n";
  }
}
