import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int n;
	n = readln.chomp.to!int;
	while (n) {
		auto a = new int[9][9];
		auto b = new int[9][9];
		auto c = new int[9][9];
		auto ans = new bool[9][9];
		int s, t;
		foreach (i; 0..9) {
			a[i] = readln.split.map!(to!int).array;
			c[s][(i%3)*3..(i%3)*3+3] = a[i][0..3];
			c[s+1][(i%3)*3..(i%3)*3+3] = a[i][3..6];
			c[s+2][(i%3)*3..(i%3)*3+3] = a[i][6..9];
			foreach (j; 0..9) {
				b[j][i] = a[i][j];
			}
			if ((i+1) % 3 == 0) s += 3;
			t = ++t % 3;
		}

		foreach (i; 0..9) {
			foreach (j; 0..9) {
				foreach (k; 0..9) {
					if (j == k) continue;
					if (a[i][j] == a[i][k]) ans[i][j] = ans[i][k] = 1;
					if (b[i][j] == b[i][k]) ans[j][i] = ans[k][i] = 1;
					if (c[i][j] == c[i][k]) ans[i/3*3 + j/3][(i%3)*3 + (j%3)] = ans[i/3*3 + k/3][(i%3)*3 + (k%3)] = 1;
				}
			}
		}

		foreach (i; 0..9) {
			foreach (j; 0..9) {
				write(ans[i][j] ? "*" : " ", a[i][j]);
			}
			writeln("");
		}
		if (--n) writeln("");
	}
}