#include <iostream>
#define BOARD_SIZE 9
#define CELL_SIZE 3

void init1(int a[BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) a[i] = 0;
}

void init2(bool a[BOARD_SIZE][BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		for (int j=0; j<BOARD_SIZE; j++) a[i][j] = false;
	}
}

void check_vertical(int board[BOARD_SIZE][BOARD_SIZE], bool v[BOARD_SIZE][BOARD_SIZE])
{
	int appeared[BOARD_SIZE];
	
	for (int j=0; j<BOARD_SIZE; j++) {
		init1(appeared);
		for (int i=0; i<BOARD_SIZE; i++) appeared[board[i][j]-1]++;
		for (int i=0; i<BOARD_SIZE; i++) {
			if (appeared[board[i][j]-1] > 1) v[i][j] = true;
		}
	}
}

void check_horizontal(int board[BOARD_SIZE][BOARD_SIZE], bool v[BOARD_SIZE][BOARD_SIZE])
{
	int appeared[BOARD_SIZE];
	
	for (int i=0; i<BOARD_SIZE; i++) {
		init1(appeared);
		for (int j=0; j<BOARD_SIZE; j++) appeared[board[i][j]-1]++;
		for (int j=0; j<BOARD_SIZE; j++) {
			if (appeared[board[i][j]-1] > 1) v[i][j] = true;
		}
	}
}

void check_cell(int board[BOARD_SIZE][BOARD_SIZE], bool v[BOARD_SIZE][BOARD_SIZE])
{
	int appeared[BOARD_SIZE];
	
	for (int c=0; c<BOARD_SIZE; c++) {
		init1(appeared);
		int offseti = (c/CELL_SIZE) * CELL_SIZE;
		int offsetj = (c%CELL_SIZE) * CELL_SIZE;
		for (int i=0; i<CELL_SIZE; i++) {
			for (int j=0; j<CELL_SIZE; j++) appeared[board[offseti + i][offsetj + j]-1]++;
		}
		for (int i=0; i<CELL_SIZE; i++) {
			for (int j=0; j<CELL_SIZE; j++) {
				if (appeared[board[offseti + i][offsetj + j]-1] > 1) v[offseti + i][offsetj + j] = true;
			}
		}
	}
}

int main()
{
	int board[BOARD_SIZE][BOARD_SIZE];
	bool violates[BOARD_SIZE][BOARD_SIZE];
	int n;
	std::cin >> n;
	for (int k=0; k<n; k++) {
		
		for (int i=0; i<BOARD_SIZE; i++) {
			for (int j=0; j<BOARD_SIZE; j++) std::cin >> board[i][j];
		}
		init2(violates);
		
		check_vertical(board, violates);
		check_horizontal(board, violates);
		check_cell(board, violates);
		
		if (k>0) std::cout << std::endl;
		for (int i=0; i<BOARD_SIZE; i++) {
			for (int j=0; j<BOARD_SIZE; j++) {
				if (violates[i][j]) std::cout << "*";
				else std::cout << " ";
				std::cout << board[i][j];
			}
			std::cout << std::endl;
		}
	}
	return 0;
}


