#include<iostream>
#include<set>
#include<utility>

typedef std::pair<int, int> P;

bool ver[9][9], hor[9][9], sq[9][9];
int n;
char puzzle[9][9];
std::set<int> s[3][9];

// k: 0 -> ver, 1 -> hor, 2 -> sq
int f( int k, int i, int j )
{
	switch( k )
	{
		case 0:
			return j;
		case 1:
			return i;
		case 2:
			return i / 3 * 3 + j / 3;
	}
}

int main()
{
	std::cin >> n;

	bool fst = true;
	while( n-- )
	{
		memset( ver, false, sizeof( ver ) );
		memset( hor, false, sizeof( hor ) );
		memset( sq, false, sizeof( sq ) );
		for( int i = 0; i != 3; ++i )
			for( int j = 0; j != 9; ++j )
				s[i][j].clear();

		for( int i = 0; i != 9; ++i )
		{
			for( int j = 0; j != 9; ++j )
			{
				std::cin >> puzzle[i][j];
	
				int t = puzzle[i][j] - '1';
				int fl = ver[f(0, i, j)][t] | ( hor[f(1, i, j)][t] << 1 ) | ( sq[f(2, i, j)][t] << 2 );

				if( !fl ) 
					ver[f(0, i, j)][t] = hor[f(1, i, j)][t] = sq[f(2, i, j)][t] = true;
				else
				{
					for( int k = 0; k != 3; ++k )
						if( fl >> k & 1 )
							s[k][f(k, i, j)].insert( t );
				}
			}
		}

		if( !fst )
			std::cout << std::endl;

		for( int i = 0; i != 9; ++i )
		{
			for( int j = 0; j != 9; ++j )
			{
				bool fl = false;
				for( int k = 0; k != 3; ++k )
					fl |= s[k][f(k, i, j)].count( puzzle[i][j] - '1' );

				std::cout << ( fl ? '*' : ' ' ) << puzzle[i][j]; 
			}
			
			std::cout << std::endl;
		}

		fst = false;
	}

	return 0;
}