#include <iostream>
using namespace std;
#define REP(i,b,c) for(int i=0;i<b;i+=c)

int main(){
	char p[9][9];
	int n;
	cin >> n;
	while(n--){
		char a[9][9];
		REP(i,9,1)REP(j,9,1)a[j][i]=' ';
		REP(i,9,1)REP(j,9,1)cin >> p[j][i];
		
		REP(j,9,3){
			REP(i,9,3){			
				int c[9]={0};
				REP(x,3,1){
					REP(y,3,1){
						c[p[i+x][j+y]-'0'-1]++;
						if(c[p[i+x][j+y]-'0'-1]>1){
							REP(t,3,1){
								REP(l,3,1){
									if(p[i+x][j+y]==p[i+t][j+l]){
										a[i+t][j+l]='*';
									}
								}
							}
						}
					}
				}	
			}
		}
		REP(i,9,1){
			int c[9]={0},c2[9]={0};
			REP(j,9,1){
				c[p[j][i]-'0'-1]++;
				if(c[p[j][i]-'0'-1]>1){
					REP(t,9,1){
						if(p[j][i]==p[t][i]){
							a[t][i]='*';
						}
					}
				}
				c2[p[i][j]-'0'-1]++;
				if(c2[p[i][j]-'0'-1]>1){
					REP(t,9,1){
						if(p[i][j]==p[i][t]){
							a[i][t]='*';
						}
					}
				}
			}
		}
		REP(i,9,1){
			REP(j,9,1)cout << a[j][i] << p[j][i];
			cout << endl;
		}
		cout << endl;
	}
}
		