#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int a[]={0,1,2};
int main(){
	int n;
	cin>>n;
	rep(u,n){
		vector<vint> vv;
		vector<vint> ans;
		initvv(ans,9,9);
		initvv(vv,9,9);
		rep(i,9){
			rep(j,9){
				cin>>vv[i][j];
				ans[i][j]=0;
			}
		}
		rep(i,9){
			vint t(10,0);
			rep(j,9){
				t[vv[i][j]]++;
			}
			rep(j,9){
				if(t[vv[i][j]]>1){
					ans[i][j]=1;
				}
			}
		}
		rep(i,9){
			vint t(10,0);
			rep(j,9){
				t[vv[j][i]]++;
			}
			rep(j,9){
				if(t[vv[j][i]]>1){
					ans[j][i]=1;
				}
			}
		}
		rep(i,3){
			rep(j,3){
				int x=i*3,y=j*3;
				vint t(10,0);
				rep(k,3){
					rep(l,3){
						t[vv[k+x][l+y]]++;
					}
				}
				rep(k,3){
					rep(l,3){
						if(t[vv[k+x][l+y]]>1){
							ans[k+x][l+y]=1;
						}
					}
				}
			}

		}
		rep(i,9){
			rep(j,9){
				if(ans[i][j]==1){
					cout<<"*";
				}
				else cout<<" ";
				cout<<vv[i][j];
			}
			cout<<endl;
		}
		if(u!=n-1) cout<<endl;

	}
}