#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(p,n){
    vector<vector<bool> >flag(10,vb(10,true));
    vvi v(10,vi(10,0));
    rep(i,9)rep(j,9)cin>>v[i][j];
    for(int i=0;i<9;i++){
        vb used(10,false);
        for(int j=0; j<9;j++){
            if(!used[v[i][j]]){used[v[i][j]]=true;}
            else {
                flag[i][j]=false;
                rep(k,9)if(v[i][k]==v[i][j])flag[i][k]=false;
            }
        }
    }
    for(int j=0;j<9;j++){
        vb used(10,false);
        for(int i=0; i<9;i++){
            if(!used[v[i][j]]){used[v[i][j]]=true;}
            else {
                flag[i][j]=false;
                rep(k,9)if(v[k][j]==v[i][j])flag[k][j]=false;
            }
        }
    }
   
    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++){
                    if(!used[v[i][j]])used[v[i][j]]=true;
                    else for(int k=h; k<h+3;k++){
                            for(int m=w; m<w+3;m++){
                                if(v[k][m]==v[i][j])flag[k][m]=false;
                        }
                    }
                }
            }
        }
    }
        cout<<endl;
    rep(i,9){
        rep(j,9){
            if(flag[i][j])cout<<" ";
            else cout<<"*";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
};