#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in();
	REP(i, n) {
		if (i != 0)cout << endl;
		int inpt[9][9]; REP(j, 9)REP(k, 9)inpt[j][k] = in();
		bool dpl[9][9]; REP(j, 9)REP(k, 9)dpl[j][k] = false;
		REP(j, 9) {
			int cnt[9] = { 0,0,0,0,0,0,0,0,0 };
			REP(k, 9)++cnt[inpt[j][k] - 1];
			REP(k, 9)if (cnt[inpt[j][k] - 1] > 1)dpl[j][k] = true;
		}
		REP(k, 9) {
			int cnt[9] = { 0,0,0,0,0,0,0,0,0 };
			REP(j, 9)++cnt[inpt[j][k] - 1];
			REP(j, 9)if (cnt[inpt[j][k] - 1] > 1)dpl[j][k] = true;
		}
		REP(j, 3) {
			REP(k, 3) {
				int cnt[9] = { 0,0,0,0,0,0,0,0,0 };
				for (ll l = j * 3; l < j * 3 + 3; ++l) for (ll m = k * 3; m < k * 3 + 3; ++m) ++cnt[inpt[l][m] - 1];
				for (ll l = j * 3; l < j * 3 + 3; ++l) for (ll m = k * 3; m < k * 3 + 3; ++m) if (cnt[inpt[l][m] - 1] > 1)dpl[l][m] = true;
			}
		}
		REP(j, 9) {
			REP(k, 9) cout << (dpl[j][k] ? '*' : ' ') << inpt[j][k];
			cout << endl;
		}
	}
}
