#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;cin>>n;
    rep(hoge,n){
    vvi v(11,vi(11,0));
    rep(i,9)rep(j,9)cin>>v[i][j];
    //rep(i,9){rep(j,9)cout<<v[i][j];cout<<endl;}
    vector<vector<bool> >flag(10,vb(10,true));
    rep(j,9){
        vb used(10,false);
        rep(i,9){
            if(used[v[i][j]]==true)
            {flag[i][j]=false;
            rep(k,9)if(v[i][j]==v[k][j])flag[k][j]=false;
            }
            else used[v[i][j]]=true;
        }
    }
    rep(i,9){
        vb used(10,false);
        rep(j,9){
            if(used[v[i][j]]==true){flag[i][j]=false;
                rep(k,9)if(v[i][j]==v[k][j])flag[k][j]=false;}
            else used[v[i][j]]=true;
        }
    }

      for(int h=0;h<=8;h+=3){
        for(int w=0; w<=8;w+=3){
            vb used(10,false);
            for(int i=h;i<h+3;i++){
                for(int j=w; j<w+3;j++){
                    used[v[i][j]]=true;
                }
            }
            for(int i=h;i<h+3;i++)
                for(int j=w;j<w;j++){
                    if(used[v[i][j]]==true){
                        flag[i][j]=false;
                        for(int l=h;l<h+3;l++)
                            for(int m=w;m<w+3;m++)
                                if(v[l][m]==v[i][j])flag[l][m]=false;
                    }
                    else used[v[i][j]]=true;
                }
        }
    }
    rep(i,9){
        rep(j,9){
            if(!flag[i][j])cout<<"*";
            else cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
    }
    
}