#include <iostream>
#include <string.h>
using namespace std;

int n;
int a[9][9];
bool b[9][9], c[9];

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		memset(b, 0, sizeof(b));

		for (int j = 0; j < 9; j++)
			for (int k = 0; k < 9; k++)
				cin >> a[j][k];

		for (int j = 0; j < 9; j++) {
			memset(c, 0, sizeof(c));
			for (int k = 0; k < 9; k++) {
				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = k - 1;
					while (u > 0 && a[j][u] != a[j][k])
						u--;
					b[j][u] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int k = 0; k < 9; k++) {
			memset(c, 0, sizeof(c));
			for (int j = 0; j < 9; j++) {
				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = j - 1;
					while (u > 0 && a[u][k] != a[j][k])
						u--;
					b[u][k] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int s = 0; s < 9; s++) {
			memset(c, 0, sizeof(c));
			for (int t = 0; t < 9; t++) {
				int j = t / 3 + (s / 3) * 3, k = t % 3 + (s % 3) * 3;

				if (c[a[j][k] - 1]) {
					b[j][k] = 1;
					int u = t - 1, v = u / 3 + (s / 3) * 3, w = u % 3 + (s % 3) * 3;
					while (u > 0 && a[v][w] != a[j][k]) {
						u--;
						v = u / 3 + (s / 3) * 3;
						w = u % 3 + (s % 3) * 3;
					}
					b[v][w] = 1;
				}
				else
					c[a[j][k] - 1] = 1;
			}
		}

		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				if (b[j][k])
					cout << "*";
				else
					cout << " ";

				cout << a[j][k];
			}
			cout << endl;
		}

		if (i != n - 1)
			cout << endl;
	}

	return 0;
}
