#include <bits/stdc++.h>
using namespace std;
long long int grid[1002][1002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int temp1, n, temp2, x, y, b, temp, q, d, k, mod = 1e9 + 7, m, a, c;
  cin >> n;
  long long int cnt = 0, count = 0;
  for (long long int i = 0; i < n; i++) {
    if (count == 4) {
      cnt = grid[i - 1][n - 1] + 1;
      count = 0;
    } else {
      if (i != 0) cnt = grid[i - 1][0] + 1;
    }
    for (int j = 0; j < n; j++) {
      grid[i][j] = cnt;
      cnt += 4;
    }
    count++;
  }
  for (long long int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
