//暴力
#include <iostream>
#include <algorithm>
#include <string> using namespace std;
const int N = ;
string s1[N], s2[N], s3[N], s4[N];
int a[N][N], b[N][N]; int main()
{
int n;
cin >> n;
for (int i = ; i<n; i++)
cin >> s1[i];
cin.get();
for (int i = ; i<n; i++)
cin >> s2[i];
cin.get();
for (int i = ; i<n; i++)
cin >> s3[i];
cin.get();
for (int i = ; i<n; i++)
cin >> s4[i]; for (int i = ; i<n; i++)
for (int j = ; j < n; j++){
//只有两种方式
a[i][j] = (i + j) % == ? : ;
b[i][j] = (i + j) % ? : ;
}
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
a[i][j] += , b[i][j] += ; //比较
int ans = 1e9;
int f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != a[i][j]) + (s2[i][j] != a[i][j]) + (s3[i][j] != b[i][j]) + (s4[i][j] != b[i][j]);
ans = min(ans, f);
f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != a[i][j]) + (s2[i][j] != b[i][j]) + (s3[i][j] != a[i][j]) + (s4[i][j] != b[i][j]);
ans = min(ans, f);
f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != a[i][j]) + (s2[i][j] != b[i][j]) + (s3[i][j] != b[i][j]) + (s4[i][j] != a[i][j]);
ans = min(ans, f);
f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != b[i][j]) + (s2[i][j] != a[i][j]) + (s3[i][j] != a[i][j]) + (s4[i][j] != b[i][j]);
ans = min(ans, f);
f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != b[i][j]) + (s2[i][j] != a[i][j]) + (s3[i][j] != b[i][j]) + (s4[i][j] != a[i][j]);
ans = min(ans, f);
f = ;
for (int i = ; i<n; i++)
for (int j = ; j<n; j++)
f += (s1[i][j] != b[i][j]) + (s2[i][j] != b[i][j]) + (s3[i][j] != a[i][j]) + (s4[i][j] != a[i][j]);
ans = min(ans, f);
cout<< ans <<endl;
system("pause");
return ;
}