#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n][n];
  int blocks = n / 4;
  int num = 0;
  for (int i = 0; i < blocks; i++) {
    for (int j = 0; j < blocks; j++) {
      int ei = i * 4;
      int ej = j * 4;
      int hold = num * 16;
      for (int x = 0; x < 4; x++) {
        for (int y = 0; y < 4; y++) {
          arr[ei + x][ej + y] = 4 * x + y + hold;
        }
      }
      num++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << arr[i][j] << ' ';
    }
    cout << endl;
  }
}
