#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	cin>>n;
	rep(i,0,n){
		if(i) cout<<endl;
		int data[9][9]={},error[9][9]={};
		rep(j,0,9) rep(k,0,9) cin>>data[j][k];
		rep(j,0,9){
			int count[9]={};
			rep(k,0,9) count[data[j][k]-1]++;
			rep(k,0,9){
				if(count[data[j][k]-1]>1) error[j][k]=1;

			}
		}rep(j,0,9){
			int count[9]={};
			rep(k,0,9) count[data[k][j]-1]++;
			rep(k,0,9){
				if(count[data[k][j]-1]>1) error[k][j]=1;
			}
		}rep(j,0,3)rep(k,0,3){
			int count[9]={};
			rep(l,0,3)rep(m,0,3) count[data[3*j+l][3*k+m]-1]++;
			rep(l,0,3)rep(m,0,3){
				if(count[data[3*j+l][3*k+m]-1]>1) error[3*j+l][3*k+m]=1;
			}
		}rep(j,0,9){
			rep(k,0,9){
				if(error[j][k]) cout<<"*";
				else cout<<" ";
				cout<<data[j][k];
			}
			cout<<endl;
		}
	}
}