#include <iostream>
#include <cstring>
using namespace std;

int dataset_count;
int sudoku[9][9];
bool wrong[9][9];
int main() {
	cin >> dataset_count;
	while (dataset_count--) {
		memset(wrong, 0, sizeof(wrong));
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				cin >> sudoku[i][j];
			}
		}
		
		// 横
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				for (int k = 0; k < 9; k++) {
					if (sudoku[i][j] == sudoku[i][k] && j != k) {
						wrong[i][j] = wrong[i][k] = true;
					}
				}
			}
		}
		
		// 縦
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				for (int k = 0; k < 9; k++) {
					if (sudoku[j][i] == sudoku[k][i] && j != k) {
						wrong[j][i] = wrong[k][i] = true;
					}
				}
			}
		}

		// ブロック
		for (int i = 0; i < 9; i+=3) {
			for (int j = 0; j < 9; j+=3) {
				for (int k = i; k < i+3; k++) {
					for (int l = j; l < j+3; l++) {
						for (int m = i; m < i+3; m++) {
							for (int n = j; n < j+3; n++) {
								if (sudoku[k][l] == sudoku[m][n] && k != m && l != n) {
									wrong[k][l] = wrong[m][n] = true;
								}
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				if (wrong[i][j]) cout << '*';
				else cout << ' ';
				cout << sudoku[i][j];
			}
			cout << endl;
		}
		if (dataset_count != 0) {
			cout << endl;
		}
	}

	return 0;
}