/*****include*****/
#include <iostream>
#include <set>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
/*****変数置き場*****/
	int n;
	int field[11][11];
	bool wrong[10];
	bool fail[11][11];
	int table_x[] = {0,1,2,0,1,2,0,1,2};
	int table_y[] = {0,0,0,1,1,1,2,2,2};
	set <int>appear;
	/*****処理部*****/
	cin >> n;
	while(n>0){
		n--;
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++){
				field[i][j] = 0;
				fail[i][j] = 0;
			}
		for(int i=0;i<10;i++)
			wrong[i] = false;
		for(int i=1;i<=9;i++)
			for(int j=1;j<=9;j++)
				cin >> field[i][j];
		appear.clear();
		
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				if(appear.find(field[i][j]) != appear.end()){
					wrong[field[i][j]] = true;
				}else
					appear.insert(field[i][j]);
			}
			appear.clear();
			for(int k=1;k<=9;k++)
				if(wrong[field[i][k]])
					fail[i][k] = true;
			for(int k=0;k<10;k++){
				wrong[k] = false;
			}
		}
		for(int j=1;j<=9;j++){
			for(int i=1;i<=9;i++){
				if(appear.find(field[i][j]) != appear.end()){
					wrong[field[i][j]] = true;
				}else
					appear.insert(field[i][j]);
			}
			appear.clear();
			for(int k=1;k<=9;k++)
				if(wrong[field[k][j]])
					fail[k][j] = true;
			for(int k=0;k<10;k++){
				wrong[k] = false;
			}
		}

		for(int i=1;i<=9;i+=3)
			for(int j=1;j<=9;j+=3){
				for(int k=0;k<9;k++)
					if(appear.find(field[i+table_y[k]][j+table_x[k]]) != appear.end())
						wrong[field[i+table_y[k]][j+table_x[k]]] = true;
					else
						appear.insert(field[i+table_y[k]][j+table_x[k]]);
				appear.clear();
				for(int k=0;k<9;k++)
					if(wrong[field[i+table_y[k]][j+table_x[k]]])
						fail[i+table_y[k]][j+table_x[k]] = true;
				for(int k=0;k<10;k++){
					wrong[k] = false;
				}
			}
		
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				if(fail[i][j])
					cout << "*";
				else
					cout << " ";
				cout << field[i][j];
			}
			cout << endl;
		}
		if(n!=0)	cout << endl;
	}
	/*****処理終了後*****/
	return 0;
}