#include<bits/stdc++.h>
using namespace std;
int n;
char a[15][15],b[15][15],c[15][15],d[15][15];
//图案按顺时针转90度
//图案按逆时针旋转270度
bool work1()
{for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)b[j][n-i+1]=a[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[i][j]!=c[i][j])return 0;return 1;
}
//图案按顺时针旋转180度
//图案按逆时针旋转180度
bool work2()
{for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)b[n-i+1][n-j+1]=a[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[i][j]!=c[i][j])return 0;return 1;
}
//图案按顺时针旋转270度
//图案按逆时针旋转90度
bool work3()
{for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)b[n-j+1][i]=a[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[i][j]!=c[i][j])return 0;return 1;
}
//图案在水平方向翻转
bool work4()
{for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)b[i][n-j+1]=a[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[i][j]!=c[i][j])return 0;return 1;
}
//组合:图案在水平方向翻转,然后再按照 1-3中的一种再次转换
bool work5()
{work4();for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=b[i][j]; if(work1())return 1;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=b[i][j]; if(work2())return 1;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=b[i][j]; if(work3())return 1;return 0;
}
//不改变
bool work6()
{for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[i][j]!=c[i][j])return 0;return 1;
}
//无效转换
void work()
{if(work1()){cout<<1;return ;}if(work2()){cout<<2;return ;}if(work3()){cout<<3;return ;}if(work4()){cout<<4;return ;}if(work5()){cout<<5;return ;}if(work6()){cout<<6;return ;}cout<<7;
}
int main()
{cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){cin>>a[i][j];d[i][j]=a[i][j];}for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>c[i][j];work();return 0; //完美的结束QAQ
}