// Arup Guha
// 6/21/2019
// Solution to Diamonds in the Rough 2017 UCF HS Problem

// Written in SI@UCF Comp Sci Camp to illustrate catching an exception,
// 2D array work, and breaking down a program into methods.

import java.util.*;
import java.io.*;

public class diamond {
	
	// Constants to make code easier to read.
	final public static int FORWARD = 0;
	final public static int BACKWARD = 1;
	
	// Useful constants for my two directions of movement.
	final public static int[] DX = {1,1};
	final public static int[] DY = {-1,1};
	final public static char[] DIAG = {'/','\\'};
	
	// Part of my object.
	private int r;
	private int c;
	private char[][] grid;
	private boolean[][] printIt;
	
	// Create a diamond object.
	public diamond(String[] input) {
		
		// Set these from String array.
		r = input.length;
		c = input[0].length();
		
		// Just allocate the char arrays.
		grid = new char[r][];
		
		// Read each line and convert to char arrays.
		for (int i=0; i<r; i++)
			grid[i] = input[i].toCharArray();
		
		// We just want this to be false at first.
		printIt = new boolean[r][c];
	}
	
	// Checks if the line starting at x, y for len in the direction dir, is a valid diamond line.
	public boolean check(int x, int y, int len, int dir) {
		
		// Where I am starting.
		int curx = x;
		int cury = y;
		
		// Go to len characters.
		for (int i=0; i<len; i++) {
			
			// Must be a forward slash.
			if (grid[curx][cury] != DIAG[dir])
				return false;
			
			// Go to next x, y.
			curx += DX[dir];
			cury += DY[dir];
		}		
		
		// If we made it here, we are good!
		return true;
	}
	
	public void mark(int x, int y, int len, int dir) {
		
		// Where I am starting.
		int curx = x;
		int cury = y;
		
		// Mark each character on this line.
		for (int i=0; i<len; i++) {
			printIt[curx][cury] = true;
			
			// Go to next x, y.
			curx += DX[dir];
			cury += DY[dir];
		}		
	}
	
	public boolean isDiamond(int x, int y, int len) {
		
		// First check if this is even in bounds.
		if (!inbounds(x, y, len)) return false;
		
		// If it's inbounds, then we need to check this.
		return check(x, y, len, FORWARD) && check(x+len, y+len, len, FORWARD) && 
		       check(x+len, y-len+1, len, BACKWARD) && check(x, y+1, len, BACKWARD);
	}
	
	// If x, y, len specifies a diamond, it marks it.
	public void markDiamond(int x, int y, int len) {
		if (isDiamond(x, y, len)) {
			mark(x, y, len, FORWARD);
			mark(x+len, y+len, len, FORWARD);
			mark(x+len, y-len+1, len, BACKWARD);
			mark(x, y+1, len, BACKWARD);
		}
	}
	
	// Marks all possible diamonds.
	public void markAll() {
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
				for (int len=1; len<Math.min(r,c)/2+1; len++) {
					markDiamond(i, j, len);
				}
			}
		}
	}
	
	// Returns true iff a diamond starting at x, y with side length len, fits within the grid at all.
	public boolean inbounds(int x, int y, int len) {
		return y-(len-1) >= 0 && y+len < c && x >= 0 && x + (2*len-1) < r;
	}
	
	// Returns the string representation of the object desired.
	public String toString() {
		
		String res = "";
		
		// Go through each row.
		for (int i=0; i<r; i++) {

			// Will store row result here.
			char[] line = new char[c];
			
			// Go through each character.
			for (int j=0; j<c; j++) {
				line[j] = '.';
				if (printIt[i][j])
					line[j] = grid[i][j];
			}
			
			// Add it to my string.
			res = res + new String(line) + "\n";
		}
		
		// Ta da!
		return res;
	}
	
	public static void main(String[] args) {
	
		// Open file, read in the number of cases. Shoing the use of the try catch. 
		// Note that we don't need to write throws... above.
		Scanner fin = null;
		try {
			fin = new Scanner(new File("diamond.in"));
		}
		
		// Exit gracefully.
		catch (FileNotFoundException exception) {
			System.out.println("Sorry, the file diamond.in is not in the proper place.");
			System.exit(0);
		}
		
		// Get the number of cases.
		int numCases = fin.nextInt();
		
		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {
			
			// Read in the information to form the grid.
			int myr = fin.nextInt();
			int myc = fin.nextInt();
			String[] grid = new String[myr];
			for (int i=0; i<myr; i++)
				grid[i] = fin.next();
			
			// Create the diamond object.
			diamond mine = new diamond(grid);
			
			// Mark all diamonds.
			mine.markAll();
			
			// Output the result.
			System.out.println("Slab #"+loop+":");
			System.out.print(mine);
		}	
	}
}