import sys

def translateCharacter(operation,character):
	dictionary = {
		'<':{
			'<':'v',
			'>':'^',
			'^':'<',
			'v':'>',
			'o':'o',
			'x':'x',
			'|':'-',
			'-':'|',
			'/':'\\',
			'\\':'/',
		},
		'>':{
			'<':'^',
			'>':'v',
			'^':'>',
			'v':'<',
			'o':'o',
			'x':'x',
			'|':'-',
			'-':'|',
			'/':'\\',
			'\\':'/',
		},
		'-':{
			'<':'<',
			'>':'>',
			'^':'v',
			'v':'^',
			'o':'o',
			'x':'x',
			'|':'|',
			'-':'-',
			'/':'\\',
			'\\':'/',
		},
		'|':{
			'<':'>',
			'>':'<',
			'^':'^',
			'v':'v',
			'o':'o',
			'x':'x',
			'|':'|',
			'-':'-',
			'/':'\\',
			'\\':'/',
		},
		'\\':{
			'<':'^',
			'>':'v',
			'^':'<',
			'v':'>',
			'o':'o',
			'x':'x',
			'|':'-',
			'-':'|',
			'/':'/',
			'\\':'\\',
		},
		'/':{
			'<':'v',
			'>':'^',
			'^':'>',
			'v':'<',
			'o':'o',
			'x':'x',
			'|':'-',
			'-':'|',
			'/':'/',
			'\\':'\\',
		},
	}
	#print('operation:',operation)
	#print('character:',character)
	return dictionary[operation][character]

def printDisplay(display):
	for i in display:
		sequence = ''
		for j in i:
			sequence +=j
			sequence += ' '
		print(sequence)
			
		


def main(userInput):
	#print(userInput)
	index = 0
	operations = userInput[len(userInput)-1]
	display = []
	for i in userInput:
		
		if(len(userInput)-1 == index):
			break
		temp = []
		for j in i:
			temp.append(j)
		display.append(temp)
		index += 1
		
	n = len(display)
	newDisplay= []
	for i in range(n):
		temp = []
		for j in range(n):
			temp.append(0)
		newDisplay.append(temp)
	printDisplay(display)
	print('')
	for operation in operations.split(' '):
		if(operation == '<'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					newY = n - x
					#print(newY)
					newDisplay[y][newY-1]=translateCharacter('<',character)
		if(operation == '>'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					newX = n - y
					newDisplay[newX-1][x]=translateCharacter('>',character)
		if(operation == '|'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					newY = n - y
					newDisplay[x][newY-1]=translateCharacter('|',character)
		if(operation == '-'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					newX = n -x
					newDisplay[newX-1][y]=translateCharacter('-',character)
		if(operation == '\\'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					
					newDisplay[y][x]=translateCharacter('\\',character)
		if(operation == '/'):
			for x,row in enumerate(display):
				for y,character in enumerate(row):
					newX = n-y
					newY = n-x
					newDisplay[newX-1][newY-1]=translateCharacter('/',character)
					
		printDisplay(newDisplay)
		print('')
		display = newDisplay
	
	#printDisplay(display)
	
			

def input():
	line = 'a'
	index = 0
	howMany = 0
	userInput = []
	while line:
		line = sys.stdin.readline()
		line = line.rstrip('\n')
		if(index == 0):
			if(line != ''):
				howMany = int(line)+1
			
		if(index != 0):
			userInput.append(line)
			
		if(index == howMany):
			main(userInput)
			userInput= []
			index  = 0
		else:
			index += 1

input()
