#include <iostream>
#include <string.h>
using namespace std;

const int COL_SIZE = 9;
const int ROW_SIZE = 9;

void inputBoard( int board[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		for( int j = 0; j < COL_SIZE; ++j ){
			cin >> board[ i ][ j ];
		}
	}
}

void outputBoard( int board[][ COL_SIZE ], bool check[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		for( int j = 0; j < COL_SIZE; ++j ){
			cout << ( check[ i ][ j ] ? '*' : ' ' ) << board[ i ][ j ];
		}
		cout << endl;
	}
}

enum{
	COL = 0,
	ROW,
	BLOCK
};

bool investigate( int board[][ COL_SIZE ], bool check[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		int usedNumber[ 3 ][ 10 ];
		memset( usedNumber, 0, sizeof(usedNumber) );
		for( int j = 0; j < COL_SIZE; ++j ){
			usedNumber[ COL ][ board[ i ][ j ] ]++;
			usedNumber[ ROW ][ board[ j ][ i ] ]++;
			usedNumber[ BLOCK ][ board[ ( i / 3 ) * 3 + j / 3 ][ ( i % 3 ) * 3 + j % 3 ] ]++;
		}
		for( int j = 0; j < COL_SIZE; ++j ){
			if( usedNumber[ COL ][ board[ i ][ j ] ] > 1 ){
				check[ i ][ j ] = true;
			}
			if( usedNumber[ ROW ][ board[ j ][ i ] ] > 1 ){
				check[ j ][ i ] = true;
			}
			int y = ( i / 3 ) * 3 + j / 3;
			int x = ( i % 3 ) * 3 + j % 3;
			if( usedNumber[ BLOCK][ board[ y ][ x ] ] > 1 ){
				check[ y ][ x ] = true;
			}
		}
	}
	return false;
}

int main()
{
	int n;
	cin >> n;
	for( int i = 0; i < n; ++i ){
		int board[ ROW_SIZE ][ COL_SIZE ];
		bool check[ ROW_SIZE ][ COL_SIZE ];
		memset( check, 0, sizeof(check) );
		inputBoard( board );
		investigate( board, check );
		if( i != 0 ){
			cout << endl;
		}
		outputBoard( board, check );
	}
	return 0;
}