// Arup Guha
// 5/2/2014
// Solution to UCF HS Contest Problem: Dragon Fire

import java.util.*;
import java.io.*;

public class fire {

	public static int R;
	public static int C;
	public static char[][] grid;
	public static boolean[][] fire;

	// For up down movements in counter-clockwise order.
	final public static int[] DX = {-1,0,1,0};
	final public static int[] DY = {0,-1,0,1};

	// For diagonal movements - one extra slot given so no need to use mod later.
	final public static int[] DIAGDX = {-1,-1,1,1,-1};
	final public static int[] DIAGDY = {1,-1,-1,1,1};

	// Also counter-clockwise order.
	final public static String ARROWS = "^<V>";

	public static void main(String[] args) throws Exception {

		Scanner fin = new Scanner(new File("fire.in"));

		// Process all cases.
		int numCases = fin.nextInt();
		for (int loop=1; loop<=numCases; loop++) {

			R = fin.nextInt();
			C = fin.nextInt();
			grid = new char[R][];
			fire = new boolean[R][C];
			for (int i=0; i<R; i++)
				grid[i] = fin.next().toCharArray();

			// Print out solution.
			char[][] ans = solve();
			System.out.println("Map #"+loop+":");
			for (int i=0; i<R; i++)
				System.out.println(new String(ans[i]));
			System.out.println();
		}

		fin.close();
	}

	// Returns the solution to the problem.
	public static char[][] solve() {

		// Find each dragon and update the grid due to it.
		for (int i=0; i<R; i++) {
			for (int j=0; j<C; j++) {
				if (grid[i][j] != '.' && grid[i][j] != 'X') {
					char[][] tmp = copy(grid);
					fill(tmp, i , j);
					update(tmp);
				}
			}
		}

		// Form our answer grid using the list of squares with fire.
		char[][] ans = new char[R][C];
		for (int i=0; i<R; i++)
			for (int j=0; j<C; j++)
				ans[i][j] = fire[i][j] ? 'F':grid[i][j];

		return ans;
	}

	public static boolean inbounds(int x, int y) {
		return x >= 0 && y >= 0 && x <R && y < C;
	}

	// Fills the line in g starting at (x,y) in the direction dir.
	public static void fillLine(char[][] g, int x, int y, int dir) {
		for (int i=x,j=y;inbounds(i,j); i+=DX[dir],j+=DY[dir]) {
			if (g[i][j] == '.' || g[i][j] == 'F')
				g[i][j] = 'F';
			else
				break;
		}
	}

	// Does the initial fire fill in g from square (x,y).
	public static void fill(char[][] g, int x, int y) {

		// Loop through possible directions.
		for (int myDir=0; myDir<ARROWS.length(); myDir++) {

			if (grid[x][y] == ARROWS.charAt(myDir)) {

				// The straight line.
				fillLine(g,x+DX[myDir],y+DY[myDir], myDir);

				// Diagonal fire clockwise side.
				goDiag(g,x,DIAGDX[myDir],y,DIAGDY[myDir], myDir);

				// Diagonal fire counterclockwise side.
				goDiag(g,x,DIAGDX[myDir+1],y,DIAGDY[myDir+1], myDir);
			}
		}
	}

	// Runs the diagonal spread of fire in g from (x,y) in direction (dx,dy) with straight direction myDir
	public static void goDiag(char[][] g, int x, int dx, int y, int dy, int myDir) {
		for (int step=1;inbounds(x+step*dx,y+step*dy); step++) {
			if (g[x+step*dx][y+step*dy] == '.')
				fillLine(g,x+step*dx,y+step*dy, myDir);
			else
				break;
		}
	}

	// Fill in trues everywhere there is fire.
	public static void update(char[][] board) {
		for (int i=0; i<R; i++)
			for (int j=0; j<C; j++)
				if (board[i][j] == 'F')
					fire[i][j] = true;
	}

	public static char[][] copy(char[][] a) {
		char[][] c = new char[a.length][a[0].length];
		for (int i=0; i<a.length; i++)
			for (int j=0; j<a[0].length; j++)
				c[i][j] = a[i][j];
		return c;
	}
}