#include <iostream>
using namespace std;

char p[9][9],m[9][9];

void vertical(int ti,int tj){
	for(int i=ti+1;i<9;i++)
		if(p[ti][tj] == p[i][tj])
			m[ti][tj] = m[i][tj] = '*';
}

void horizontal(int ti,int tj){
	for(int j=tj+1;j<9;j++)
		if(p[ti][tj] == p[ti][j])
			m[ti][tj] = m[ti][j] = '*';
}

void square(int ti,int tj){
	for(int k=(ti%3)*3+tj%3+1;k<9;k++){
		int i=ti/3*3+k/3, j=tj/3*3+k%3;
		if(p[ti][tj] == p[i][j])
			m[ti][tj] = m[i][j] = '*';
	}
}

int main(void){
	int i,j,n,set;

	cin>>n;
	for(set=0;n--;set++){
		if(set!=0) cout<<endl;
		for(i=0;i<9;i++){
			for(j=0;j<9;j++){
				cin>>p[i][j];
				m[i][j] = ' ';
			}
		}

		for(i=0;i<9;i++){
			for(j=0;j<9;j++){
				vertical(i,j);
				horizontal(i,j);
				square(i,j);

				cout<<m[i][j];
				cout<<p[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}