import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

bool test(int[][] m, int x, int y) {
	foreach(i; 0..9) {
		if(i != y && m[x][i] == m[x][y]) {
			return false;
		}
		if(i != x && m[i][y] == m[x][y]) {
			return false;
		}
	}
	int X = (x/3)*3;
	int Y = (y/3)*3;
	foreach(i; 0..3) {
		foreach(j; 0..3) {
			if((X+i != x || Y+j != y) && m[x][y] == m[X+i][Y+j]) {
				return false;
			}
		}
	}
	return true;
}

void main(){
	int N = readInt();
	foreach(t; 0..N) {
		if(t){ 
			writeln();
		}
		int[][] m;
		foreach(i; 0..9) {
			m ~= readInts();
		}
		bool[9][9] g;
		foreach(i; 0..9) {
			foreach(j; 0..9) {
				g[i][j] = test(m, i, j);
			}
		}
		foreach(i; 0..9) {
			foreach(j; 0..9) {
				write(g[i][j] ? " ": "*");
				write(m[i][j]);
			}
			writeln();
		}
	}
}