#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << endl << flush;
		}
		int hyou[9][9][2] = {0};
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				cin >> hyou[j][k][0];
			}
		}
		int hantei3[9][9] = {0};
		for (int j = 0; j < 9; j++) {
			int hantei[9] = {0};
			int hantei2[9] = {0};
			int p;
			for (int k = 0; k < 9; k++) { 
				hantei[hyou[j][k][0]-1]++; // yoko
			    hantei2[hyou[k][j][0]-1]++; // tate
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				hantei[p][hyou[j][k][0]-1]++;
			}
			for (int k = 0; k < 9; k++) {
				if (hantei[hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
				if (hantei2[hyou[k][j][0]-1] > 1) {
					hyou[k][j][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			int p;
			for (int k = 0; k < 9; k++) { 
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				if (hantei3[p][hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				if (hyou[j][k][1] > 0) {
					cout << "*" << flush;
				} else {
					cout << " " << flush;
				}
				cout << hyou[j][k][0] << flush;
			}
			cout << endl << flush; 
		}
	}
	return 0;
}