import java.util.*; class Display { static char rows[][]; static char tempRows[][]; static char temp[][]; static int n; public static void main(String args[]) { Scanner in = new Scanner(System.in); while(true) { if(!in.hasNextInt()) break; n = in.nextInt(); in.nextLine(); rows = new char[n][n]; tempRows = new char[n][n]; for(int i = 0; i < n; i++) { rows[i] = in.nextLine().toCharArray(); } String instructions[] = in.nextLine().split(" "); for(int i = 0; i < instructions.length; i++) { if(instructions[i].equals("<")) rotateLeft(); if(instructions[i].equals(">")) rotateRight(); if(instructions[i].equals("|")) flipVertical(); if(instructions[i].equals("-")) flipHorizontal(); if(instructions[i].equals("\\")){ flipVertical(); rotateLeft(); } if(instructions[i].equals("/")){ flipVertical(); rotateRight(); } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { System.out.print(rows[i][j]); } System.out.print("\n"); } } } public static void rotateLeft() { for(int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(rows[i][j] == '<') rows[i][j] = 'v'; else if(rows[i][j] == 'v') rows[i][j] = '>'; else if(rows[i][j] == '>') rows[i][j] = '^'; else if(rows[i][j] == '^') rows[i][j] = '<'; else if(rows[i][j] == '-') rows[i][j] = '|'; else if(rows[i][j] == '|') rows[i][j] = '-'; else if(rows[i][j] == '/') rows[i][j] = '\\'; else if(rows[i][j] == '\\') rows[i][j] = '/'; tempRows[n-j-1][i] = rows[i][j]; } } moveTemp(); } public static void rotateRight() { for(int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(rows[i][j] == '<') rows[i][j] = '^'; else if(rows[i][j] == 'v') rows[i][j] = '<'; else if(rows[i][j] == '>') rows[i][j] = 'v'; else if(rows[i][j] == '^') rows[i][j] = '>'; else if(rows[i][j] == '-') rows[i][j] = '|'; else if(rows[i][j] == '|') rows[i][j] = '-'; else if(rows[i][j] == '/') rows[i][j] = '\\'; else if(rows[i][j] == '\\') rows[i][j] = '/'; tempRows[j][n-i-1] = rows[i][j]; } } moveTemp(); } public static void flipVertical() { for(int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(rows[i][j] == '<') rows[i][j] = '>'; else if(rows[i][j] == '>') rows[i][j] = '<'; else if(rows[i][j] == '/') rows[i][j] = '\\'; else if(rows[i][j] == '\\') rows[i][j] = '/'; tempRows[i][n-j-1] = rows[i][j]; } } moveTemp(); } public static void flipHorizontal() { for(int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(rows[i][j] == '^') rows[i][j] = 'v'; else if(rows[i][j] == 'v') rows[i][j] = '^'; else if(rows[i][j] == '/') rows[i][j] = '\\'; else if(rows[i][j] == '\\') rows[i][j] = '/'; tempRows[n-i-1][j] = rows[i][j]; } } moveTemp(); } public static void moveTemp() { temp = tempRows; tempRows = rows; rows = temp; } }