#include #define M(t,x,y) t[((y)*(size))+(x)]; int main() { for(;;) { int size = 0; scanf( "%d", &size ); if( !size ) return 0; char *matrix = new char [ size * size + 1 ]; char *target = new char [ size * size + 1 ]; for( int i = 0; i < size; i++ ) { scanf( "%s", matrix + i * size ); } for( int i = 0; i < size; i++ ) { scanf( "%s", target + i * size ); } int X, Y; for( int x = 0; x < size; x++ ) { for( int y = 0; y < size; y++ ) { X = x; Y = y; if( matrix[X*size+Y] == 'O' ) { printf( "%c", target[x*size+y] ); } } } for( int x = 0; x < size; x++ ) { for( int y = 0; y < size; y++ ) { X = size - y - 1; Y = x; if( matrix[X*size+Y] == 'O' ) { printf( "%c", target[x*size+y] ); } } } for( int x = 0; x < size; x++ ) { for( int y = 0; y < size; y++ ) { X = size - x - 1; Y = size - y - 1; if( matrix[X*size+Y] == 'O' ) { printf( "%c", target[x*size+y] ); } } } for( int x = 0; x < size; x++ ) { for( int y = 0; y < size; y++ ) { X = y; Y = size - x - 1; if( matrix[X*size+Y] == 'O' ) { printf( "%c", target[x*size+y] ); } } } printf( "\n" ); } };