#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	int n, table[9][9];
	bool ok[9][9];
	cin >> n;
	for (int cnt = 0; cnt < n; cnt++){
		for (int i = 0; i < 9; i++){
			for (int j = 0; j < 9; j++){
				cin >> table[i][j];
				ok[i][j] = true;
			}
		}
		
		cout << "input ok" << endl;
		// れつ
		for (int i = 0; i < 9; i++){
			bool done[10] = {false};
			for (int j = 0; j < 9; j++){
				if (done[table[i][j]]){
					ok[i][j] = false;
					for (int k = 0; k < j; k++){
						if (table[i][j] == table[i][k]){
							ok[i][k] = false;
						}
					}
				}
				done[table[i][j]] = true;
			}
		}
		
		// ぎょう
		for (int i = 0; i < 9; i++){
			bool done[10] = {false};
			for (int j = 0; j < 9; j++){
				if (done[table[j][i]]){
					ok[j][i] = false;
					for (int k = 0; k < j; k++){
						if (table[j][i] == table[k][i]){
							ok[k][i] = false;
						}
					}
				}
				done[table[j][i]] = true;
			}
		}
		
		for (int y = 0; y < 9; y += 3){
			for (int x = 0; x < 9; x += 3){
				bool done[10] = {false};
				for (int i = 0; i < 3; i++){
					for (int j = 0; j < 3; j++){
						int ny = y + i, nx = x + j;
						// printf("%d ", table[ny][nx]);
						if (done[table[ny][nx]]){
							ok[ny][nx] = false;
							for (int k = 0; k < 3; k++){
								for (int l = 0; l < 3; l++){
									if (table[ny][nx] == table[y + k][x + l]){
										ok[y + k][x + l] = false;
									}
								}
							}
						}
						done[table[ny][nx]] = true;
					}
					// cout << endl;
				}
				// cout << endl;
			}
		}
		
		for (int i = 0; i < 9; i++){
			for (int j = 0; j < 9; j++){
				printf("%c%d", ok[i][j] ? ' ' : '*', table[i][j]);
			}
			cout << endl;
		}
		
		if (cnt + 1 < n) cout << endl;
	}
	
	return 0;
}