#include <bits/stdc++.h>
using namespace std;
char a[5][108][108];
vector<int> p;
int c[208][208];
int res = 1e9;
int n;
void calc() {
  for (int x = 0; x < 4; x++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (p[x] == 1) {
          c[i][j] = a[x + 1][i][j];
        } else if (p[x] == 2) {
          c[i][j + n] = a[x + 1][i][j];
        } else if (p[x] == 3) {
          c[i + n][j] = a[x + 1][i][j];
        } else if (p[x] == 4) {
          c[i + n][j + n] = a[x + 1][i][j];
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= 2 * n; i++) {
    for (int j = 1; j <= 2 * n; j++) {
      cnt += ((i + j) % 2 != c[i][j] % 2);
    }
  }
  res = min(res, cnt);
  cnt = 0;
  for (int i = 1; i <= 2 * n; i++) {
    for (int j = 1; j <= 2 * n; j++) {
      cnt += ((i + j + 1) % 2 != c[i][j] % 2);
    }
  }
  res = min(res, cnt);
}
int main() {
  cin >> n;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) cin >> a[i][j] + 1;
  }
  for (int i = 1; i <= 4; i++) p.push_back(i);
  do {
    calc();
  } while (next_permutation(p.begin(), p.end()));
  cout << res;
}
