#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long nCr(long long n, long long r) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1];
  return C[r];
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  long long m = sqrt(n);
  for (long long i = 3; i <= m; i += 2)
    if (n % i == 0) return false;
  return true;
}
long long M(long long a) { return (a % (1000000007LL)); }
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<vector<int> > > piece(
      4, vector<vector<int> >(n, vector<int>(n, 0)));
  vector<vector<int> > actual1(2 * n, vector<int>(2 * n, 0));
  vector<vector<int> > actual2(2 * n, vector<int>(2 * n, 0));
  for (long long i = 0; i < (long long)(2 * n); ++i)
    for (long long j = 0; j < (long long)(2 * n); ++j) {
      if ((i + j) & 1)
        actual1[i][j] = 0;
      else
        actual1[i][j] = 1;
    }
  for (long long i = 0; i < (long long)(2 * n); ++i)
    for (long long j = 0; j < (long long)(2 * n); ++j) {
      if ((i + j) & 1)
        actual2[i][j] = 1;
      else
        actual2[i][j] = 0;
    }
  char c;
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[0][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[1][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[2][i][j] = (int)(c - '0');
    }
  for (long long i = 0; i < (long long)(n); ++i)
    for (long long j = 0; j < (long long)(n); ++j) {
      cin >> c;
      piece[3][i][j] = (int)(c - '0');
    }
  string pat = "ABCD";
  int ans = (1000000007LL);
  do {
    int change1 = 0, change2 = 0;
    for (long long i = 0; i < (long long)(4); ++i) {
      for (long long j = 0; j < (long long)(n); ++j)
        for (long long k = 0; k < (long long)(n); ++k) {
          if (i == 0) {
            if (actual1[j][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 1) {
            if (actual1[j][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 2) {
            if (actual1[j + n][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          } else if (i == 3) {
            if (actual1[j + n][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change1++;
          }
        }
    }
    for (long long i = 0; i < (long long)(4); ++i) {
      for (long long j = 0; j < (long long)(n); ++j)
        for (long long k = 0; k < (long long)(n); ++k) {
          if (i == 0) {
            if (actual2[j][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 1) {
            if (actual2[j][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 2) {
            if (actual2[j + n][k] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          } else if (i == 3) {
            if (actual2[j + n][k + n] == piece[pat[i] - 'A'][j][k])
              continue;
            else
              change2++;
          }
        }
    }
    ans = min(ans, min(change1, change2));
  } while (next_permutation(begin(pat), end(pat)));
  cout << ans;
  return 0;
}
