#include <iostream>
using namespace std;
int fld[9][9];

bool judge(int x, int y){
	for(int i = 0; i < 9; ++i){
		if(i != x){
			if(fld[i][y] == fld[x][y]){
				return false;
			}
		}
	}
	
	for(int i = 0; i < 9; ++i){
		if(i != y){
			if(fld[x][i] == fld[x][y]){
				return false;
			}
		}
	}
	
	int _x = (x / 3) * 3;
	int _y = (y / 3) * 3;
	
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			if(_x + i != x || _y + j != y){
				if(fld[_x + i][_y + j] == fld[x][y]){
					return false;
				}
			}
		}
	}
	
	return true;
}

int main(){
	int n;
	
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		
		for(int x = 0; x < 9; ++x){
			for(int y = 0; y < 9; ++y){
				cin >> fld[x][y];
			}
		}
		
		if(i) cout << endl;
		for(int x = 0; x < 9; ++x){
			for(int y = 0; y < 9; ++y){
				cout << (judge(x, y) ? " " : "*") << fld[x][y];
			}
			cout << endl;
		}
	}
	
	return 0;
}