#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

void cnc(int q[9], int ct[10]){
	rep(i,10) ct[i] = 0;
	rep(i,9) ct[q[i]]++;
}

int main(void){

  int n;
	int st[9][2] ={{0,0},{0,3},{0,6},{3,0},{3,3},{3,6},{6,0},{6,3},{6,6}};
	while(cin >> n){
		bool kg=false;
		if(cin.eof()) break;
		int w[9][9]={0};
		
		rep(i,n){
			if(kg) cout << endl;
			rep(j,9) rep(k,9) cin >> w[j][k];
			int wk[9]={0}, wt[10]={0};
			bool rr[9][9]={false};
			rep(j,9){
				rep(k,9) wk[k] = w[j][k];
				cnc(wk,wt);
				rep(k,9) if(wt[w[j][k]] > 1) rr[j][k]=true;

				rep(k,9) wk[k] = w[k][j];
				cnc(wk,wt);
				rep(k,9) if(wt[w[k][j]] > 1) rr[k][j]=true;

				rep(k,9) wk[k] = w[st[j][0]+k/3][st[j][1]+k%3];
				cnc(wk,wt);
				rep(k,9) if(wt[w[st[j][0]+k/3][st[j][1]+k%3]] > 1) rr[st[j][0]+k/3][st[j][1]+k%3]=true;
			}
			rep(j,9) rep(k,9){
				cout << (rr[j][k]? "*": " ");
				cout << w[j][k];
				cout << (k>7? "\n": "");
			}
			kg=true;
		}
	}
	return 0;
	
}