#include <iostream>
#include <cstring>

using namespace std;

int dx[3]={0,3,6};
int dy[3]={0,3,6};

int main(void){
	int n;
	bool first = true;;
	cin >> n;
	
	for(int i=0;i<n;i++){
		int mat[9][9];
		bool ast[9][9];
		int worksp[10];
		
		
		if(!first) cout << endl;
		memset(ast, false, sizeof(ast));
		for(int j=0;j<9;j++){
			for(int k=0;k<9;k++){
				cin >> mat[j][k];
			}
		}
		
		//check every rows
		for(int j=0;j<9;j++){
			memset(worksp, -1, sizeof(worksp));
			
			for(int k=0;k<9;k++){
				if(worksp[mat[j][k]] == -1){ //unexist yet
					worksp[mat[j][k]] = k;
				}else{
					ast[j][k] = true;
					ast[j][worksp[mat[j][k]]] = true;
					//cout << "line " << mat[j][k] << endl;
				}
			}
		}
		//check every cols
		for(int j=0;j<9;j++){
			memset(worksp, -1, sizeof(worksp));
			
			for(int k=0;k<9;k++){
				if(worksp[mat[k][j]] == -1){ //unexist yet
					worksp[mat[k][j]] = k;
				}else{
					ast[k][j] = true;
					ast[worksp[mat[k][j]]][j] = true;
					//cout << "cols " << mat[k][j] << endl;
				}
			}
		}
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				memset(worksp, -1, sizeof(worksp));
				
				for(int p=0;p<3;p++){
					for(int q=0;q<3;q++){
						if(worksp[mat[dx[j]+p][dy[k]+q]] == -1){
							worksp[mat[dx[j]+p][dy[k]+q]] = p*10+q;
						}else{
							ast[dx[j]+p][dy[k]+q] = true;
							ast[dx[j] + worksp[mat[dx[j]+p][dy[k]+q]] / 10][dy[k] + worksp[mat[dx[j]+p][dy[k]+q]] % 10] = true;
						}
					}
				}
			}
		}
		//check every square
		
		for(int j=0;j<9;j++){
			for(int k=0;k<9;k++){
				if(ast[j][k]){
					cout << "*" << mat[j][k];
				}else{
					cout << " " << mat[j][k];
				}
			}
			cout << endl;
		}
		first = false;
	}
}