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

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

bool used[3][9][9];
int n;
char puzzle[9][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( used, false, sizeof( used ) );
		
		std::set<int> s[3][9];
		
		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 = 0;
				for( int k = 0; k != 3; ++k )
					fl |= (used[k][f(k,i,j)][t] << k);

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

		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;
}