//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
int N;
char up[1010][1010], tmp[1010][1010];
char arr[1010][1010];
void rotate()
{
for(int i = 0; i < N; i++)
for(int j = 0, k = N - 1; j < N; j++, k--)
tmp[i][j] = up[k][i];
memcpy(up, tmp, sizeof(up));
/*for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
cout<<up[i][j];
cout<<endl;
}*/
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
cin>>N;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
cin>>up[i][j];
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
cin>>arr[i][j];
int oprt = 4;
while(oprt--)
{
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(up[i][j] == 'O')
cout<<arr[i][j];
rotate();
}
return 0;
}