#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
const int N = 9;

vector <string> disp_res (vector <vector <int> > t, vector <vector<bool> > c )
{
	int size = t.size();
	int len  = t[0].size();
	int i,j;
	vector <string> res (size);

	for (i = 0; i < size; ++i ){
		for (j = 0; j < len; ++j ){
			if (c[i][j]){
//				cout << ' ' << t[i][j];
				res[i] += ' ';
			}else{
				res[i] += '*';
//				cout << '*' << t[i][j];
			} // end if
			res[i] += (t[i][j] + '0');
		} // end for
//		cout << endl;
	} // end for

	return res;
}

void iscorrect (vector <vector <int> > b, vector <vector <bool> >& c )
{
	int i,j,k,m;

	// search hight
	for (j = 0; j < N; ++j){
		vector <vector <int> > used(N + 1);
		for (i = 0; i < N; ++i){
//			cout << b[i][j] << ' ';
			used[b[i][j]].push_back(i);
		} // end for
//		cout << endl;
		for (m = 1; m <= N; ++m){
			if (!used[m].empty() && used[m].size() == 1){
				continue;
			} // end if
			if (!used[m].empty() && used[m].size() > 1){
				for (k = 0; k < used[m].size(); ++k){
					c[used[m][k]][j] = false;
				} // end if
			} // end if
		} // end for
		used.clear();	
	} // end for

	// search width
	for (i = 0; i < N; ++i){
		vector <vector <int> > used(N + 1);
		for (j = 0; j < N; ++j){
//			cout << b[i][j] << ' ';
			used[b[i][j]].push_back(j);
		} // end for
//		cout << endl;
		for (m = 1; m <= N; ++m){
			if (!used[m].empty() && used[m].size() == 1){
				continue;
			} // end if
			if (!used[m].empty() && used[m].size() > 1){
				for (k = 0; k < used[m].size(); ++k){
					c[i][used[m][k]] = false;
				} // end if
			} // end if
		} // end for
		used.clear();	
	} // end for

	// search block
	for (i = 0; i < N; i += 3){
		for (j = 0; j < N; j += 3){
			vector <vector <int> > used (N + 1);
			for (k = 0; k < N; ++ k){
				int row = i + k / 3;
				int col = j + (k % 3);
//				cout << b[row][col] << ' ';
				used[b[row][col]].push_back(k);
			} // end for
//			cout << endl;
			for (m = 1; m <= N; ++m){
				if (!used[m].empty() && used[m].size() == 1){
					continue;
				} // end if
				if (!used[m].empty() && used[m].size() > 1){
					for (k = 0; k < used[m].size(); ++k){
						c[ i + used[m][k]/3 ][ j + (used[m][k] % 3) ] = false;
					} // end if
				} // end if
			} // end for
			used.clear();	
		} // end for
	} // end for


}
template<class T> void setup (vector <vector<T> > &c, T n )
{
	int size = c.size();
	int len  = c[0].size();
	int i,j;

	for (i = 0; i < size; ++i){
		for (j = 0; j < len; ++j){
			c[i][j] = n;
		} // end for
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.suudoku", "r", stdin );
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	int i,j;

	vector <vector <int> >  b(N, vector <int>(N, 0 ) );
	vector <vector <bool> > c(N, vector <bool>(N, true ) );
	vector <vector <string> > res;

	for (i = 0; i < N*n; ++i){

		getline (cin, str );
		stringstream ss(str );

		for (j = 0; j < N; ++j){
			int num;
			ss >> num;
			b[i % N][j] = num;
		} // end for
	
		if (i % N == N - 1 ){
			iscorrect (b, c );
			vector <string> r;
			r = disp_res (b, c );
			res.push_back (r );
			setup (b, 0 );
			setup (c, true );
		} // end if
	} // end for

	int size = res.size();

	for (i = 0; i < size; ++i){
		vector<string>::iterator it = res[i].begin();
		for (; it != res[i].end(); ++it ){
			string str = (*it);
			int len = str.size();

			for (j = 0; j < len; ++j){
				cout << str[j];
			} // end for
			cout << endl;
		} // end for

		if (i != size - 1){
			cout << endl;
		} // end if

	} // end for
		
	return 0;
}

Measured memory_bytes: 0