import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Scanner;

import javax.swing.JFileChooser;

public class codeJam2 {

	public static void main(String[] args) {
		
		//Test String and set up variables.
		String input = "WWRWWRWRWLW WRWLWLWWLWW";
		int index = input.indexOf(' ');
		boolean[][][] maze = null;
		boolean[][][] result = null;
		int[] startValues = new int[3];
		Scanner s = null;
		try {
			s = new Scanner(getFile());
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		int counter = 1;
		String res = "";
		
		//Get Input File
		Writer output = null;
		File file = new File("candy.out");
		try {
			output = new BufferedWriter(new FileWriter(file));
		} catch (IOException e) {
			e.printStackTrace();
		}
		int num = s.nextInt();
		
		//Output Solution
		if(s.hasNext()) 
			s.nextLine();
		for(int z = 0; z < num; z++) {
			maze = new boolean[1000][1000][4];
			input = s.nextLine();
			System.out.println(input);
			index = input.indexOf(' ');
			String input1 = input.substring(0, index);
			String input2 = input.substring(index+1);
			startValues[0] = 2;
			startValues[1] = 500;
			startValues[2] = 0;
			startValues = solve(maze, input1, startValues);
			solve(maze, input2, startValues);
			result = trimArray(maze);
			try {
				output.write("Case #" + counter + ":\n");
			} catch (IOException e) {
				e.printStackTrace();
			}
			for(int i = 0; i < result.length; i++) {
				res = "";
				///OUTPUT CODES GIVEN BY CODE JAM PROBLEM
				for(int j = 0; j < result[0].length; j++) {
					if(result[i][j][0] && result[i][j][1] && result[i][j][2] && result[i][j][3])
						res += "f";
					else if(!result[i][j][0] && result[i][j][1] && result[i][j][2] && result[i][j][3])
						res += "e";
					else if(!result[i][j][0] && !result[i][j][1] && result[i][j][2] && result[i][j][3])
						res += "6";
					else if(!result[i][j][0] && !result[i][j][1] && !result[i][j][2] && result[i][j][3])
						res += "4";
					else if(!result[i][j][0] && result[i][j][1] && !result[i][j][2] && result[i][j][3])
						res += "c";
					else if(!result[i][j][0] && result[i][j][1] && !result[i][j][2] && !result[i][j][3])
						res += "8";
					else if(!result[i][j][0] && result[i][j][1] && result[i][j][2] && !result[i][j][3])
						res += "a";
					else if(result[i][j][0] && !result[i][j][1] && result[i][j][2] && result[i][j][3])
						res += "7";
					else if(result[i][j][0] && !result[i][j][1] && !result[i][j][2] && result[i][j][3])
						res += "5";
					else if(result[i][j][0] && !result[i][j][1] && !result[i][j][2] && !result[i][j][3])
						res += "1";
					else if(result[i][j][0] && !result[i][j][1] && result[i][j][2] && !result[i][j][3])
						res += "3";
					else if(result[i][j][0] && result[i][j][1] && !result[i][j][2] && result[i][j][3])
						res += "d";
					else if(result[i][j][0] && result[i][j][1] && !result[i][j][2] && !result[i][j][3])
						res += "9";
					else if(result[i][j][0] && result[i][j][1] && result[i][j][2] && !result[i][j][3])
						res += "b";
					else if(!result[i][j][0] && !result[i][j][1] && result[i][j][2] && !result[i][j][3])
						res += "2";
					else if(!result[i][j][0] && !result[i][j][1] && !result[i][j][2] && !result[i][j][3]) {
						System.out.println("box!");
						res += "0";
					}
					else {
						System.out.println("WTF MATE!?");
						System.out.println(result[i][j][0]);
						System.out.println(result[i][j][1]);
						System.out.println(result[i][j][2]);
						System.out.println(result[i][j][3]);
					}
				}
				try {
					output.write(res + "\n");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			counter++;
		}		
		try {
			output.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	//We start with an over-sized array because we don't know what the maze looks like.
	//After we plot the maze, this function trims the array down.
	private static boolean[][][] trimArray(boolean[][][] maze) {
		int height = 0, width = 0;
		int firstW = 0;
		for(int i = 0; i < maze.length; i++) {
			if(maze[i][500][0] || maze[i][500][1] || maze[i][500][2] || maze[i][500][3]) {
				height++;
			}
			if(maze[0][i][0] || maze[0][i][1] || maze[0][i][2] || maze[0][i][3]) {
				if(firstW == 0) {
					firstW = i;
				}
				width++;
			}
		}
		boolean[][][] newArray = new boolean[height][width][4];
		for(int i = firstW; i < firstW + width; i++) {	
			for(int j = 0; j < height; j++) {
				newArray[j][i-firstW][0] = maze[j][i][0];
				newArray[j][i-firstW][1] = maze[j][i][1];
				newArray[j][i-firstW][2] = maze[j][i][2];
				newArray[j][i-firstW][3] = maze[j][i][3];
			}
		}
		return newArray;
	}

	//Solves the solution in an enormous array.
	public static int[] solve(boolean[][][] maze, String input, int[] startValues) {
		
		//Variables
		int prev = startValues[0]; //Initial Values 0 = North, 1 = east, 2 = south, 3 = west
		int posX = startValues[1];
		int posY = startValues[2];
		int p = 1;		//Counter
		char c = ' ';	//Direction to go
		
		//Follows the instructions of the maze and keeps track of what must be true.
		while( p < input.length()) {
			c = input.charAt(p);
			if(c == 'L') {
				prev = prev + 3;
			}
			if(c == 'R') {
				if(p < input.length()-1 && input.charAt(p+1) == 'R') {
					p++;
					prev = prev + 2;
				}
				else {
					prev = prev + 1;
				}	
			}
			if(prev > 3)	//Overflow.
				prev = prev-4;
			if(prev == 0)	//North Open
				maze[posY][posX][0] = true;
			if(prev == 1)	//East Open
				maze[posY][posX][1] = true;
			if(prev == 2)	//South Open
				maze[posY][posX][2] = true;
			if(prev == 3)	//West Open
				maze[posY][posX][3] = true;
			
			if(c == 'W') {
				if(prev == 0)	//go north
					posY--;
				if(prev == 1)	//go east
					posX++;
				if(prev == 2)	//go south
					posY++;
				if(prev == 3)	//gow west
					posX--;
			}
			p++;
		}
		
		//Fix Position (Step to last spot so we can go backwards).
		if(prev == 0)
			posY++;
		if(prev == 1)
			posX--;
		if(prev == 2)
			posY--;
		if(prev == 3)
			posX++;
		prev = prev + 2;
		if(prev > 3)
			prev = prev - 4;
		
		//Return result
		int[] result = {prev, posX, posY};
		return result;
	}
	
	
	public static File getFile(){
        // create a GUI window to pick the text to evaluate
        JFileChooser chooser = new JFileChooser(".");
        int retval = chooser.showOpenDialog(null);
        File f =null;
        chooser.grabFocus();
        if (retval == JFileChooser.APPROVE_OPTION)
           f = chooser.getSelectedFile();
        return f;
    }
}
