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],
		b = new int[9][9],
		c = new int[9][9],
		ans = new bool[9][9];

		foreach (i; 0..9) {
			a[i] = readln.split.map!(to!int).array;
			foreach (j; 0..3) {
				c[i/3*3+j][(i%3)*3..(i%3)*3+3] = a[i][j*3..(j+1)*3];
			}
			foreach (j; 0..9) {
				b[j][i] = a[i][j];
			}
		}

		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("");
	}
}