#include<iostream>
#define BOARD_LEN 9
using namespace std;

void Rule_Col(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	for(int i = 0; i < BOARD_LEN; ++i){
		for(int j = 0; j < BOARD_LEN; ++j){
			int t = board[j][i];
			for(int k = 0; k < BOARD_LEN; ++k){
				if( k == j )
					continue;
				if( t == board[k][i] )
					bad[k][i] = 1;
			}
		}
	}
}
void Rule_Row(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	for(int i = 0; i < BOARD_LEN; ++i){
		for(int j = 0; j < BOARD_LEN; ++j){
			int t = board[i][j];
			for(int k = 0; k < BOARD_LEN; ++k){
				if( k == j )
					continue;
				if( t == board[i][k] )
					bad[i][k] = 1;
			}
		}
	}
}
void Rule_Square(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	const int ai[] = {1,4,7};
	const int aj[] = {1,4,7};

	for(int i = 0; i < sizeof(ai)/sizeof(*ai); ++i){
		for(int j = 0; j < sizeof(aj)/sizeof(*aj); ++j){
			const int di[] = {-1,0,1,-1,0,1,-1,0,1};
			const int dj[] = {-1,-1,-1,0,0,0,1,1,1};
			for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
				int t = board[ai[i]+di[k]][aj[j]+dj[k]];
				for(int l = 0; l < sizeof(di)/sizeof(*di); ++l){
					if( k == l )
						continue;
					if( t == board[ai[i]+di[l]][aj[j]+dj[l]] )
						bad[ai[i]+di[l]][aj[j]+dj[l]] = 1;
				}
			}
		}
	}
}
int main(void){
	int n;
	bool bFirst = true;

	cin >> n;
	for(int D = 0; D < n; ++D){
		int bad[BOARD_LEN][BOARD_LEN] ={{0,},};
		int board[BOARD_LEN][BOARD_LEN];

		if( bFirst )
			bFirst = false;
		else
			cout << '\n';

		for(int i = 0; i < sizeof(board)/sizeof(*board); ++i){
			for(int j = 0; j < sizeof(*board)/sizeof(**board); ++j){
				cin >> board[i][j];
			}
		}
		Rule_Col( board, bad );
		Rule_Row( board, bad );
		Rule_Square( board, bad );
		for(int i = 0; i < sizeof(board)/sizeof(*board); ++i){
			for(int j = 0; j < sizeof(*board)/sizeof(**board); ++j){
				if( bad[i][j] )
					cout << '*';
				else
					cout << ' ';
				cout << board[i][j];
			}
			cout << '\n';
		}
	}
	return 0;
}