#include <bits/stdc++.h>

using namespace std;


int UsedData[10];
int PuzzleData[9][9];
bool judgeResult[9][9];

void checkDataByRow(int row) {
	
	for (int t = 1; t < 10; t++) {
		if (UsedData[t] == 1) {
			continue;
		}
		for (int j = 0; j < 9; j++) {
			if (PuzzleData[row][j] == t) {
				judgeResult[row][j] = true;
			}
		}
	}
}

void checkDataByCol(int col) {
	
	for (int t = 1; t < 10; t++) {
		if (UsedData[t] == 1) {
			continue;
		}
		for (int j = 0; j < 9; j++) {
			if (PuzzleData[j][col] == t) {
				judgeResult[j][col] = true;
			}
		}
	}
}

void checkDataBySquare(int startI, int startJ) {

	memset(UsedData, 0, sizeof(UsedData));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			UsedData[PuzzleData[startI + i][startJ + j]]++;
		}
	}

	for (int t = 1; t < 10; t++) {
		if (UsedData[t] == 1) {
			continue;
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (PuzzleData[startI + i][startJ + j] == t) {
					judgeResult[startI + i][startJ + j] = true;
				}
			}
		}
	}
}

void show() {
	
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++) {
			
			cout << (judgeResult[i][j] ? "*" : " ") << PuzzleData[i][j];
		}
		cout << endl;
	}
}

int main() {
	int n;

	cin >> n;
	while (n--) {
		memset(judgeResult, false, sizeof(judgeResult));
		for (int i = 0; i < 9; i++) {
			memset(UsedData, 0, sizeof(UsedData));
			for (int j = 0; j < 9; j++) {
				cin >> PuzzleData[i][j];
				UsedData[PuzzleData[i][j]]++;
			}
			checkDataByRow(i);
		}
		for (int i = 0; i < 9; i++) {
			memset(UsedData, 0, sizeof(UsedData));
			for (int j = 0; j < 9; j++) {
				UsedData[PuzzleData[j][i]]++;
			}
			checkDataByCol(i);
		}
		for (int i = 0; i < 7; i += 3) {
			for (int j = 0; j < 7; j += 3) {
				checkDataBySquare(i, j);
			}
		}

		show();
		if (n != 0) {
			cout << endl;
		}
	}



	return 0;
}
