// Arup Guha
// 1/27/2022
// Alternate Solution to CS2 Homework: Tentaizu

import java.util.*;

public class tentaizu_alt {

	// Necessary constants.
	final public static int N = 7;
	final public static int NUMBOMBS = 10;
	
	// For adjacent bomb directions.
	final public static int[] DX = {-1,-1,-1,0,0,1,1,1};
	final public static int[] DY = {-1,0,1,-1,1,-1,0,1};
	
	// Will store the board here.
	public static char[][] board;
	
	// Location (i,j) will store the # of bombs currently adjacent to location (i,j).
	public static int[][] curAdjBombs;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			// Read in board.
			board = new char[N][];
			for (int i=0; i<N; i++)
				board[i] = stdin.next().toCharArray();
		
			// Case header.
			System.out.println("Tentaizu Board #"+loop+":");
			
			// Set this up.
			curAdjBombs = new int[N][N];
			
			// Solve it!
			go(0, NUMBOMBS);
			
			// Print board.
			print();
			
			// Blank line after each case.
			System.out.println();
		}
	}
	
	// Solves the board with the first k positions fixed having to place bombs more bombs in the future
	// squares.
	public static boolean go(int k, int bombs) {
	
		// No more bombs to place, so we can evaluate the whole board to see if this is a solution.
		if (bombs == 0) return isConsistent();
		
		// Since we screened out the 0 bomb case above, so this means no solution.
		if (k == N*N) return false;
		
		// We know that slot k-1 is filled, so anything that is finalized due to it has to be correct.
		// If it isn't, we cut out.
		if (incorrect(k-1)) return false;
	
		// We're not allowed to put a bomb here since it has a number so move on.
		if (Character.isDigit(board[k/N][k%N])) return go(k+1, bombs);
		
		// Place the bomb and adjust our adjacent bomb count.
		board[k/N][k%N] = '*';
		addAdj(k, 1);
		
		// Recurse on this board.
		boolean res = go(k+1, bombs-1);
		
		// If it worked, stop and return true.
		if (res) return true;
		
		// Undo bomb and adjust adjacent bomb count.
		board[k/N][k%N] = '.';
		addAdj(k, -1);
		
		// Whatever this answer is, is our final answer.
		return go(k+1, bombs);
	}
	
	// Returns if the current board is fully consistent with the input.
	public static boolean isConsistent() {
	
		// See for any discrepancies.
		for (int i=0; i<N; i++) 
			for (int j=0; j<N; j++) 
				if (Character.isDigit(board[i][j]) && (board[i][j]-'0') != curAdjBombs[i][j])
					return false;
			
		// Good if we get here.
		return true;
	}
	
	// Returns true if the location(s) finalized by location loc are incorrect.
	public static boolean incorrect(int loc) {
	
		// Extract location.
		int x = loc/N;
		int y = loc%N;
		
		// Nothing is incorrect yet.
		if (x == 0) return false;
		
		// Now we can go up and left, so this square is finalized.
		if (y > 0 && Character.isDigit(board[x-1][y-1]) && (board[x-1][y-1]-'0') != curAdjBombs[x-1][y-1])
			return true;
		
		// When we finish a row, we also finalize the character above us.
		if (y == N-1 && Character.isDigit(board[x-1][y]) && (board[x-1][y]-'0') != curAdjBombs[x-1][y])
			return true;
			
		// We're okay if we get here (ie it's not incorrect.)
		return false;
	}
	
	public static void addAdj(int loc, int val) {
		
		// For readability
		int x = loc/N;
		int y = loc%N;
		
		// Go to each adjacent square and add val.
		for (int i=0; i<DX.length; i++) {
			if (!inbounds(x+DX[i], y+DY[i])) continue;
			curAdjBombs[x+DX[i]][y+DY[i]] += val;
		}
	}
	
	// Returns true iff (x,y) is inbounds.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < N && y >= 0 && y < N;
	}
	
	// Prints the board.
	public static void print() {
		for (int i=0; i<N; i++)
			System.out.println(new String(board[i]));
	}
}