#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define D(a) cerr << ">>> " << #a << " >" << a << "<" << endl; #define R1(a) scanf("%d", &a); #define R2(a) scanf("%d%d", &a,&b); #define R3(a) scanf("%d%d%d", &a,&b,&c); #define DR1(a) int a;scanf("%d", &a); #define DR2(a) int a,b;scanf("%d%d", &a,&b); #define DR3(a) int a,b,c;scanf("%d%d%d", &a,&b,&c); #define INF 1.0e20 typedef long long int ll; typedef pair pii; typedef vector vi; int N; char command; char matrix[100][100]; char tmpMatrix[100][100]; void printMatrix() { FOR(i,0,N-1) { FOR(j,0,N-1) { printf("%c", matrix[i][j]); } printf("\n"); } } char transformRotLeft(char c) { switch(c) { case '<': return 'v'; case '^': return '<'; case '>': return '^'; case 'v': return '>'; case '|': return '-'; case '-': return '|'; case '/': return '\\'; case '\\': return '/'; default: return c; } } void rotateLeft() { FOR(i,0,N-1) { FOR(j,0,N-1) { tmpMatrix[N-j-1][i] = transformRotLeft(matrix[i][j]); } } FOR(i,0,N-1) { FOR(j,0,N-1) { matrix[i][j] = tmpMatrix[i][j]; } } } char transformRotRight(char c) { switch(c) { case '<': return '^'; case '^': return '>'; case '>': return 'v'; case 'v': return '<'; case '|': return '-'; case '-': return '|'; case '/': return '\\'; case '\\': return '/'; default: return c; } } void rotateRight() { FOR(i,0,N-1) { FOR(j,0,N-1) { tmpMatrix[j][N-i-1] = transformRotRight(matrix[i][j]); } } FOR(i,0,N-1) { FOR(j,0,N-1) { matrix[i][j] = tmpMatrix[i][j]; } } } char transformHoriz(char c) { switch(c) { case '^': return 'v'; case 'v': return '^'; case '/': return '\\'; case '\\': return '/'; default: return c; } } void flipHoriz() { FOR(i,0,(N-1)/2) { FOR(j,0,N-1) { char tmp = matrix[N-i-1][j]; matrix[N-i-1][j] = transformHoriz(matrix[i][j]); matrix[i][j] = transformHoriz(tmp); } } } char transformVert(char c) { switch(c) { case '<': return '>'; case '>': return '<'; case '/': return '\\'; case '\\': return '/'; default: return c; } } void flipVert() { FOR(i,0,N-1) { FOR(j,0,(N-1)/2) { char tmp = matrix[i][N-j-1]; matrix[i][N-j-1] = transformVert(matrix[i][j]); matrix[i][j] = transformVert(tmp); } } } char transformMainDiag(char c) { switch(c) { case '<': return '^'; case '^': return '<'; case '>': return 'v'; case 'v': return '>'; case '|': return '-'; case '-': return '|'; default: return c; } } void flipMainDiag() { FOR(i,0,N-1) { FOR(j,0,i) { char tmp = matrix[j][i]; matrix[j][i] = transformMainDiag(matrix[i][j]); matrix[i][j] = transformMainDiag(tmp); } } } char transformAntiDiag(char c) { switch(c) { case '<': return 'v'; case '^': return '>'; case '>': return '^'; case 'v': return '<'; case '|': return '-'; case '-': return '|'; default: return c; } } void flipAntiDiag() { FOR(i,0,N-1) { FOR(j,0,N-i-1) { char tmp = matrix[N-j-1][N-i-1]; matrix[N-j-1][N-i-1] = transformAntiDiag(matrix[i][j]); matrix[i][j] = transformAntiDiag(tmp); } } } int main() { while(scanf("%d", &N) > 0) { getchar(); FOR(i,0,N-1) { FOR(j,0,N-1) { matrix[i][j] = getchar(); } getchar(); } while((command = getchar()) != '\n') { switch(command) { case '<': rotateLeft(); break; case '>': rotateRight(); break; case '-': flipHoriz(); break; case '|': flipVert(); break; case '\\': flipMainDiag(); break; case '/': flipAntiDiag(); break; } command = getchar(); if (command == '\n') { break; } } printMatrix(); } return 0; }