// Stephen Fulwider
// 9 July 2008
// Bomberdude problem solution for 11 July 2008 Mock Contest #1

import java.io.*;
import java.util.*;

public class bomb
{
	// class variables keep track of the maze and where we are
	int[][] maze;
	int r,c,h;
	int curR, curC;
	String path;
	int move;
	
	// maze values
	static final int OPEN = -1;
	static final int WALL = -2;
	
	// end condition values
	static final int KEEP_GOING = 0;
	static final int WIN = 1;
	static final int DIE = 2;
	static final int GAME_OVER = 3;
	
	// deltas for bomb detonations
	static final int[] DR = {0,-1,0,+1};
	static final int[] DC = {-1,0,+1,0};
	
	// create new instance of problem, read maze from file
	bomb(Scanner fin) throws IOException
	{
		r = fin.nextInt();
		c = fin.nextInt();
		h = fin.nextInt();
		
		fin.nextLine();
		
		maze = new int[r][c];
		for (int i=0; i<r; i++)
		{
			String line = fin.nextLine().trim();
			for (int j=0; j<c; j++)
			{
				if (line.charAt(j) == '.')
					maze[i][j] = OPEN;
				else if (line.charAt(j) == 'W')
					maze[i][j] = WALL;
				else
					maze[i][j] = line.charAt(j)-'0';
			}
		}
		
		path = fin.nextLine().trim();
		
		// start @ top left
		curR = curC = 0;
		// start @ first move
		move = 0;
	}
	
	int move()
	{
		// if we've exhausted all our moves but still haven't reached the exit, game over
		if (move == path.length())
			return GAME_OVER;
		
		// get the changes to curR and curC for the current move
		int dr = 0, dc = 0;
		if (path.charAt(move) == 'L') dc = -1;
		if (path.charAt(move) == 'U') dr = -1;
		if (path.charAt(move) == 'R') dc = +1;
		if (path.charAt(move) == 'D') dr = +1;
		
		// if that move can be legally made, make it
		if (isValidSpot(curR + dr, curC + dc))
		{
			curR += dr; curC += dc;
		}
		
		// if we're sitting at the final spot, we win
		if (curR == r-1 && curC == c-1)
			return WIN;
		
		// if we're sitting on a bomb, detonate it and any bombs it touches
		if (maze[curR][curC] >= 0)
			detonate(curR, curC);
		
		// if we've lost all our health, we're dead
		if (h <= 0)
			return DIE;

		// if nothing else got triggered, then go to the next move and keep going
		move++;
		return KEEP_GOING;
	}
	
	// our recursive detonate function to detonate bombs, crumble walls, decrease health, 
	//	and detonate other bombs that original bombs may trigger
	void detonate(int thisR, int thisC)
	{
		// just stop if we're off the maze
		if (!isInBounds(thisR, thisC))
			return;
		
		// if this is a wall, crumble it (make it open)
		if (maze[thisR][thisC] == WALL)
			maze[thisR][thisC] = OPEN;
		
		// if this spot is Bomberdude, decrease his health
		if (thisR == curR && thisC == curC)
			h--;
		
		// if this is a bomb, then recursively call detonate for the power of the bomb, after
		//	marking this spot no longer a bomb (so that future bombs don't also call this and
		//	create an infinite loop!)
		if (maze[thisR][thisC] >= 0)
		{
			int power = maze[thisR][thisC];
			maze[thisR][thisC] = OPEN;
			
			for (int mag=1; mag<=power; mag++)
				for (int i=0; i<DR.length; i++)
					detonate(thisR+DR[i]*mag,thisC+DC[i]*mag);
		}
	}
	
	// make sure a potential move is valid (on maze and not into a wall)
	boolean isValidSpot(int newR, int newC)
	{
		return isInBounds(newR,newC) && maze[newR][newC] != WALL;
	}
	
	// make sure a potential move is in bounds (on maze)
	boolean isInBounds(int newR, int newC)
	{
		return newR >= 0 && newR < r && newC >= 0 && newC < c;
	}
	
	// main to get it all going
	public static void main(String[] args) throws IOException
	{
		Scanner fin = new Scanner(new File("bomb.in"));
		int n = fin.nextInt();
		
		for (int mazeNum = 1; mazeNum <= n; mazeNum++)
		{
			bomb b = new bomb(fin);
			
			// keep moving as long as stopping condition not reached
			int res;
			while ((res = b.move()) == KEEP_GOING);
			
			// output what happened
			System.out.printf("Maze %d: ", mazeNum);
			if (res == WIN)
				System.out.println("You made it to the end. Great job!");
			else if (res == DIE)
				System.out.println("Oh no, you exploded!");
			else
				System.out.println("You didn't die, but you didn't win either. Lame!");
		}
		
		fin.close();

	}
}
