// Arup Guha
// 3/21/2026
// Solution to 2026 UCF HS Contest Problem L: Careening Crates

import java.util.*;
import java.io.*;

public class crates {

	public static int n;
	public static char[][] grid;

	public static void main(String[] args) throws Exception {
	
		// Get grid.
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(stdin.readLine());
		grid = new char[n][];
		for (int i=0; i<n; i++)
			grid[i] = stdin.readLine().trim().toCharArray();
		
		// For my storage system.
		HashMap<String,Integer> cmds = new HashMap<String,Integer>();
		cmds.put("BRAKE", 0);
		cmds.put("ACCELERATE", 1);
		cmds.put("LEFT", 2);
		cmds.put("RIGHT", 3);
			
		// Read in the moves using our code.
		int numC = Integer.parseInt(stdin.readLine());
		int[] moves = new int[numC];
		for (int i=0; i<numC; i++) 
			moves[i] = cmds.get(stdin.readLine().strip());
		
		// Get a list of equivalent moves.
		ArrayList<Integer> equiv = getEquiv(moves);
		
		// The first two moves matter.
		for (int i=0; i<2 && i<equiv.size(); i++)
			doMove(equiv.get(i));
		
		// So do the last two moves.
		int start = Math.max(2, equiv.size()-2);
		
		// So do these. Note that if equiv is length 1,2 or 3, this still works.
		for (int i=start; i<equiv.size(); i++)
			doMove(equiv.get(i));
			
		// Output result.
		for (int i=0; i<n; i++)
			System.out.println(new String(grid[i]));
	}

	// Returns a list of equivalent moves using the observation that any string of L-Rs
	// is equivalent to just the last item in the string. Same for A-Bs.
	public static ArrayList<Integer> getEquiv(int[] moves) {
	
		// Move useful moves here.
		ArrayList<Integer> res = new ArrayList<Integer>();
		int i = 0;
		
		// Keep going until we're done.
		while (i < moves.length) {
			
			// If we have multiple moves in the same/opposite direction, they can
			// all simplify down to one move.
			int j=i;
			while (j<moves.length && moves[j]/2 == moves[i]/2) j++;
		
			// All that matters is the last move in this list.
			res.add(moves[j-1]);
			
			// Now we start here.
			i = j;
		}
		
		// Ta da!
		return res;
	}
	
	// Execute the move here.
	public static void doMove(int idx) {
	
		// These are the up down moves. We count columns.
		if (idx/2 == 0) {
		
			// Get the count of # of items in each column.
			int[] colCnt = new int[n];
			for (int j=0; j<n; j++)
				for (int i=0; i<n; i++)
					if (grid[i][j] == '#')
						colCnt[j]++;
						
			// Slower but makes my life easier!
			for (int i=0; i<n; i++) Arrays.fill(grid[i], '.');
			
			// Redo each column.
			for (int j=0; j<n; j++) {
			
				// Start and change.
				int  x = idx == 0 ? 0 : n-1;
				int dx = idx == 0 ? 1 : -1;
			
				// Change the right number of spots to #.
				for (int i=0; i<colCnt[j]; i++) {
					grid[x][j] = '#';
					x += dx;
				}
			}
		}
		
		// Left-Right.
		else {
		
			// Get the count of # of items in each row.
			int[] rowCnt = new int[n];
			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					if (grid[i][j] == '#')
						rowCnt[i]++;
						
			// Slower but makes my life easier!
			for (int i=0; i<n; i++) Arrays.fill(grid[i], '.');
			
			// Redo each row
			for (int i=0; i<n; i++) {
			
				// Start and change.
				int  x = idx == 3 ? 0 : n-1;
				int dx = idx == 3 ? 1 : -1;
			
				// Change the right number of spots to #.
				for (int j=0; j<rowCnt[i]; j++) {
					grid[i][x] = '#';
					x += dx;
				}
			}
		
		}
	}
}