#include <iostream>
#include <cstring>

int main(){
	int n, f = 0;
	std::cin >> n;
	while(n--){
		if(f++)std::cout << "\n";
		int sudoku[9][9], map[9][9];
		memset(map, 0, sizeof(map));
		for(int i=0;i<81;i++)
			std::cin >> sudoku[i/9][i%9];
		
		int check[10][2];

		for(int i=0;i<9;i++){
			memset(check, -1, sizeof(check));
			for(int j=0;j<9;j++){
				int x = check[sudoku[i][j]][1],
					y = check[sudoku[i][j]][0];
				if(x != -1){
					map[y][x] = 1;
					map[i][j] = 1;
				}
				
				check[sudoku[i][j]][0] = i;
				check[sudoku[i][j]][1] = j;
			}
		}
		
		for(int i=0;i<9;i++){
			memset(check, -1, sizeof(check));
			for(int j=0;j<9;j++){
				int x = check[sudoku[j][i]][1],
					y = check[sudoku[j][i]][0];
				if(x != -1){
					map[y][x] = 1;
					map[j][i] = 1;
				}
				
			check[sudoku[j][i]][0] = j;
			check[sudoku[j][i]][1] = i;
			}
		}
		
		for(int i=0;i<9;i++){
			int sx = i % 3, sy = i / 3;//¶ãÌî_
			memset(check, -1, sizeof(check));
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					int x = check[sudoku[sy*3+j][sx*3+k]][1],
						y = check[sudoku[sy*3+j][sx*3+k]][0];
					if(x != -1){
						map[y][x] = 1;
						map[sy*3+j][sx*3+k] = 1;
					}
					
					check[sudoku[sy*3+j][sx*3+k]][0] = sy*3+j;
					check[sudoku[sy*3+j][sx*3+k]][1] = sx*3+k;
				}
			}
		}
		
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				if(map[i][j])
					std::cout << "*" << sudoku[i][j];
				else
					std::cout << " " << sudoku[i][j];
			}
			std::cout << "\n";
		}
	}
        return 0;
}