#include <iostream>
#include <vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	// input
	for( int t = 0; t < n; t++ ){
		int puzzle[9][9];
		int row[9][9] = {{0}}, col[9][9] = {{0}}, rect[9][9] = {{0}};
		for( int i = 0; i < 9; i++ ){
			for( int j = 0; j < 9; j++ ){
				cin >> puzzle[i][j];
				if( row[i][puzzle[i][j]-1] == 1 ) row[i][puzzle[i][j]-1] = -1;
				else row[i][puzzle[i][j]-1] = 1;
				if( col[j][puzzle[i][j]-1] == 1 ) col[j][puzzle[i][j]-1] = -1;
				else col[j][puzzle[i][j]-1] = 1;
				if( rect[i/3*3+j/3][puzzle[i][j]-1] == 1 ) rect[i/3*3+j/3][puzzle[i][j]-1] = -1;
				else rect[i/3*3+j/3][puzzle[i][j]-1] = 1;
			}
		}

		// output
		if( t != 0 ) cout << endl;
		for( int i = 0; i < 9; i++ ){
			for( int j = 0; j < 9; j++ ){
				if( row[i][puzzle[i][j]-1] == -1 || col[j][puzzle[i][j]-1] == -1 || rect[i/3*3+j/3][puzzle[i][j]-1] == -1 ) cout << "*";
				else cout << " ";
				cout << puzzle[i][j];
			}
			cout << endl;
		}
	}
}