#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
int n, a[1005][1005], cnt1 = -1, cnt2 = -1, t[4][4];
int main() {
  for (int i = 0; i < 4; i++) {
    int tot = 0;
    for (int j = i;; j = (j + 1) % 4) {
      cnt1++;
      t[i][j] = cnt1;
      tot++;
      if (tot == 4) break;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i += 4) {
    for (int j = 0; j < n; j += 4) {
      cnt2++;
      for (int ii = 0; ii < 4; ii++)
        for (int jj = 0; jj < 4; jj++)
          a[i + ii][j + jj] = cnt2 * 16 + t[ii][jj];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << a[i][j] << " ";
    cout << endl;
  }
  return 0;
}
