#include #include #include using namespace std; bool holes[1000][1000][4]; int main() { int n; cin >> n; while ( n!= 0 ) { memset( holes, false, sizeof holes); for ( int i = 0; i < n; i++ ) { string s; cin >> s; for ( int j = 0; j < n; j++ ) if ( s[j] == 'O' ) { int x = i, y = j; for ( int q = 0; q < 4; q++ ) { holes[x][y][q] = true; int tm = x; x = y; y = n - 1 - tm; } } } string decoded[4]; decoded[0] = decoded[1] = decoded[2] = decoded[3] = ""; for ( int i = 0; i < n; i++ ) { string line; cin >> line; for ( int j = 0; j < n; j++ ) { for ( int q = 0; q < 4; q++ ) if ( holes[i][j][q] ) decoded[q] += line[j]; } } cout << decoded[0] << decoded[1] << decoded[2] << decoded[3] << endl; cin >> n; } return 0; }