#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int n;
	cin>>n;
	rep(loop,n){
		if(loop>0)
			cout<<endl;
		
		vvi a(9,vi(9));
		rep(i,9) rep(j,9)
			cin>>a[i][j];
		
		vvi bad(9,vi(9));
		rep(i,9){
			vi hist(10);
			rep(j,9)
				hist[a[i][j]]++;
			rep(j,9)
				if(hist[a[i][j]]!=1)
					bad[i][j]=1;
			hist=vi(10);
			rep(j,9)
				hist[a[j][i]]++;
			rep(j,9)
				if(hist[a[j][i]]!=1)
					bad[j][i]=1;
		}
		rep(k,9){
			int offi=k/3*3,offj=k%3*3;
			vi hist(10);
			rep(i,3) rep(j,3)
				hist[a[offi+i][offj+j]]++;
			rep(i,3) rep(j,3)
				if(hist[a[offi+i][offj+j]]!=1)
					bad[offi+i][offj+j]=1;
		}
		rep(i,9){
			rep(j,9)
				cout<<(bad[i][j]?'*':' ')<<a[i][j];
			cout<<endl;
		}
	}
	
	return 0;
}