#include<iostream>
#include<string>
using namespace std;
bool a[9][9];
int c[9][9];
int main() {
	int n;
	cin >> n;
	string b;
	getline(cin, b);
	for (int x = 0; x < n; x++) {
		int d[10];
		int k;
		for (int i = 0; i < 9; i++) {
			getline(cin, b);
			for (int j = 0; j < b.length(); j+=2) {
				c[i][j / 2] = (int)b[j] - '0';
				a[i][j] = false;
			}
			if (i == 0) k = c[0][0];
			fill(d, d + 10, 0);
			for (int j = 0; j < 9; j++) 
				d[c[i][j]]++;
			for (int j = 0; j < 9; j++) {
				if (d[c[i][j]] > 1) 
					a[i][j] = true;
			}
		}
		c[0][0] = k;
		for (int i = 0; i < 9; i++) {
			fill(d, d + 10, 0);
			for (int j = 0; j < 9; j++)
				d[c[j][i]]++;
			for (int j = 0; j < 9; j++) {
				if (d[c[j][i]]>1)
					a[j][i] = true;
			}
		}
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				if (a[i][j])
					cout << "*" << c[i][j];
				else
					cout << " " << c[i][j];
			}
			cout << endl;
		}
		if (x < n-1) {
			cout << endl;
		}
	}
}