#include <iostream>
using namespace std;


int table[9][9];
bool memo[9][9];


void solve(){
	for (int i = 0; i < 9; i++){
		for (int j = 0; j < 8; j++){
			for (int k = j + 1; k < 9; k++){
				if (table[i][j] == table[i][k]) memo[i][j] = memo[i][k] = true;
				if (table[j][i] == table[k][i]) memo[j][i] = memo[k][i] = true;
			}
		}
	}
}


int main(){
	int n;

	cin >> n;

	for (int i = 0; i < n; i++){
		for (int y = 0; y < 9; y++){
			for (int x = 0; x < 9; x++){
				cin >> table[y][x];
			}
		}
		solve();

		for (int y = 0; y < 9; y++){
			for (int x = 0; x < 9; x++){
				if (memo[y][x]) cout << "*";
				else cout << " ";
				cout << table[y][x];
				if (x == 8) cout << endl;
			}
		}
		cout << endl;
	}

	return 0;
}