#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int N;
	cin>>N;
	for(int ds=0;ds<N;ds++){
		if(ds!=0) puts("");
		int fld[9][9];
		int cntX[9][9] = {}, cntY[9][9] = {}, cntA[9][9]={};
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				cin>>fld[i][j]; fld[i][j]--;
				cntY[i][fld[i][j]]++;
				cntX[j][fld[i][j]]++;
				cntA[(i/3)*3+j/3][fld[i][j]]++;
			}
		}

		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				if(cntY[i][fld[i][j]]>1 || cntX[j][fld[i][j]]>1 ||
				   cntA[(i/3)*3+j/3][fld[i][j]]>1)
					printf("*");
				else printf(" ");
				printf("%d",fld[i][j]+1);
			}puts("");
		}
	}
	return 0;
}