import sys

rotate_left = {
 '<': 'v',
 '>': '^',
 '^': '<',
 'v': '>',
 'o': 'o',
 'x': 'x',
 '|': '-',
 '-': '|',
 '\\': '/',
 '/': '\\'
}

rotate_right = { v: k for k, v in rotate_left.items()}


flip_horizontal = {
 '<': '<',
 '>': '>',
 '^': 'v',
 'v': '^',
 'o': 'o',
 'x': 'x',
 '|': '|',
 '-': '-',
 '\\': '/',
 '/': '\\'
}



flip_vertical = {
 '<': '>',
 '>': '<',
 '^': '^',
 'v': 'v',    # PRO ZASMANI
 'o': 'o',
 'x': 'x',
 '|': '|',
 '-': '-',
 '\\': '/',
 '/': '\\'
}

flip_main_diag = {
 '<': '^',
 '>': 'v',
 '^': '<',
 'v': '>',
 'o': 'o',
 'x': 'x',
 '|': '-',
 '-': '|',
 '\\': '\\',
 '/': '/'
}


flip_anti_diag = {
 '<': 'v',
 '>': '^',
 '^': '>',
 'v': '<',
 'o': 'o',
 'x': 'x',
 '|': '-',
 '-': '|',
 '\\': '\\',
 '/': '/'
}


def rotl(x, y, L):
    return (y, L - x - 1)

def rotr(x, y, L):
    return (L - y - 1, x)

def fliph(x, y, L):
    return (x, L - y - 1)

def flipv(x, y, L):
    return (L - x - 1, y)

def flipmd(x, y, L):
    return (y, x)

def flipad(x, y, L):
    return (L - y - 1, L - x - 1)

opice = {
  '<': (rotl, rotate_left),
  '>': (rotr, rotate_right),
  '-': (fliph, flip_horizontal),
  '|': (flipv, flip_vertical),
  '\\': (flipmd, flip_main_diag),
  '/': (flipad, flip_anti_diag)
}

ii = {
  '<': [1, 2, 3, 0, 5, 6, 7, 4],
  '>': [3, 0, 1, 2, 7, 4, 5, 6],
  '-': [6, 5, 4, 7, 2, 1, 0, 3],
  '|': [4, 7, 6, 5, 0, 3, 2, 1],
  '\\': [5, 4, 7, 6, 1, 0, 3, 2],
  '/': [7, 6, 5, 4, 3, 2, 1, 0]
}



def main666():
    while sys.stdin:
        try:
            n = int(input())
            lines = []
            for i in range(n):
                lines.append(input())
            ops = input().split()
            s = 0
            for op in ops:
                s = ii[op][s]

            ops = ''
            if s >= 4:
                ops += '|'
                s -= 4

            for o in range(s):
                ops += '<'


            for op in ops:
                actimel = [ [None] * n for i in range(n) ]
                f, m = opice[op]
                for vitalinea, line in enumerate(lines):
                    for i, ch in enumerate(line):
                        x, y = f(vitalinea, i, n)
                        actimel[x][y] = m[ch]
                lines = actimel
            for line in lines:
                print("".join(line))
                

        except EOFError:
            break


main666()
