#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
using namespace std;


void solve(vector<string> board){
	vector< vector<int> > flag(9, vector<int>(9, 1));
	for(int y=0;y<9;y++){
		vector<int> check(10, 0); 
		for(int x=0;x<9;x++){
			int n = board[y][x] - '0';
			check[n]++;
		}
		for(int x=0;x<9;x++){
			int n = board[y][x] - '0';
			if(check[n] > 1)flag[y][x] = false;
		}
	}
	for(int x=0;x<9;x++){
		vector<int> check(10, 0); 
		for(int y=0;y<9;y++){
			int n = board[y][x] - '0';
			check[n]++;
		}
		for(int y=0;y<9;y++){
			int n = board[y][x] - '0';
			if(check[n] > 1)flag[y][x] = false;
		}
	}
	for(int y=0;y<9;y+=3){ 
		for(int x=0;x<9;x+=3){
			vector<int> check(10, 0);
			for(int dy=0;dy<3;dy++)for(int dx=0;dx<3;dx++){
				int ny = y + dy;
				int nx = x + dx;
				int n = board[ny][nx] - '0';
				check[n]++;
			}
			for(int dy=0;dy<3;dy++)for(int dx=0;dx<3;dx++){
				int ny = y + dy;
				int nx = x + dx;
				int n = board[ny][nx] - '0';
				if(check[n] > 1)flag[ny][nx] = false;
			}
		}
	}
	for(int y=0;y<9;y++){
		for(int x=0;x<9;x++){
			if(!flag[y][x])cout << "*";
			else cout << " ";
			cout << board[y][x];
		}
		cout << endl;
	}
}

int main(){
	int n;
	scanf("%d\n", &n);
	for(int t=0;t<n;t++){
		vector<string> board;
		for(int i=0;i<9;i++){
			string tmp, str;
			getline(cin, tmp);
			for(int j=0;j<tmp.size();j++)if(tmp[j] != ' ')str += tmp[j];
			board.push_back(str);
		}
		if(t > 0)cout << endl;
		solve(board);
	}
	return 0;
}