#include #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define FORD(i,a,b) for (int i = (a); i >= (b); i--) #define REP(i,b) for (int i = 0; i < (b); i++) using namespace std; typedef long long ll; const bool debug = false; struct State { bool flipv, fliph; int rot; }; State flipv(State st) { return (State) { !st.flipv, st.fliph, (4 - st.rot) % 4 }; } State fliph(State st) { return (State) { st.flipv, !st.fliph, (4 - st.rot) % 4 }; } State rotleft(State st) { return (State) { st.flipv, st.fliph, (st.rot + 1) % 4 }; } State rotright(State st) { return (State) { st.flipv, st.fliph, (st.rot + 4-1) % 4 }; } char cflipv(char c) { if (c == '<') { return '>'; } else if (c == '>') { return '<'; } else if (c == '/') { return '\\'; } else if (c == '\\') { return '/'; } else { return c; } } char cfliph(char c) { if (c == '^') { return 'v'; } else if (c == 'v') { return '^'; } else if (c == '/') { return '\\'; } else if (c == '\\') { return '/'; } else { return c; } } char crotleft(char c) { if (c == '^') { return '>'; } else if (c == '<') { return '^'; } else if (c == 'v') { return '<'; } else if (c == '>') { return 'v'; } else if (c == '|') { return '-'; } else if (c == '-') { return '|'; } else if (c == '/') { return '\\'; } else if (c == '\\') { return '/'; } else { return c; } } char c[105][105]; char nc[105][105]; char cmdline[2000005]; int main() { int n; while (scanf("%d ", &n) == 1) { if (debug) printf("# n = %d\n", n); REP(i,n) fgets(c[i], sizeof(char) * 105, stdin); fgets(cmdline, sizeof(cmdline), stdin); State st = (State) { false, false, 0 }; for (int p = 0; ; p += 2) { char cmd = cmdline[p]; if (cmd == '\\') { st = flipv(rotright(st)); } else if (cmd == '/') { st = flipv(rotleft(st)); } else if (cmd == '|') { st = flipv(st); } else if (cmd == '-') { st = fliph(st); } else if (cmd == '<') { st = rotleft(st); } else if (cmd == '>') { st = rotright(st); } else { break; } if (debug) printf("# processed '%c', state %d %d %d\n", cmd, st.flipv, st.fliph, st.rot); } if (debug) { printf("# grid\n"); REP(i, n) { printf("#"); REP(j, n) printf(" '%c'", c[i][j]); printf("\n"); } } if (st.flipv) { REP(i, n) REP(j, n) nc[i][j] = cflipv(c[i][n-1-j]); REP(i, n) REP(j, n) c[i][j] = nc[i][j]; if (debug) { printf("# flipv\n"); REP(i, n) { printf("#"); REP(j, n) printf(" '%c'", c[i][j]); printf("\n"); } } } if (st.fliph) { REP(i, n) REP(j, n) nc[i][j] = cfliph(c[n-1-i][j]); REP(i, n) REP(j, n) c[i][j] = nc[i][j]; if (debug) { printf("# fliph\n"); REP(i, n) { printf("#"); REP(j, n) printf(" '%c'", c[i][j]); printf("\n"); } } } REP(k, (4 - st.rot) % 4) { REP(i, n) REP(j, n) nc[i][j] = crotleft(c[n-1-j][i]); REP(i, n) REP(j, n) c[i][j] = nc[i][j]; if (debug) { printf("# rot\n"); REP(i, n) { printf("#"); REP(j, n) printf(" '%c'", c[i][j]); printf("\n"); } } } if (debug) { printf("# grid\n"); REP(i, n) { printf("#"); REP(j, n) printf(" '%c'", c[i][j]); printf("\n"); } } REP(i, n) { REP(j, n) printf("%c", c[i][j]); printf("\n"); } } return 0; }