#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int n;
    cin >> n;
    rep(nind,n){
        vector<vector<int> > V(9,vector<int>(9));
        //if no -> true;
        vector<vector<bool> > flag(9,vector<bool>(9));

        rep(i,9) rep(j,9){
            cin >> V[i][j];
        }
        rep(i,9){
            vector<int> cnt(10);
            vector<int> cnt2(10);
            rep(j,9){
                cnt[V[i][j]]++;
                cnt2[V[j][i]]++;
            }
            rep(j,9){
                if(cnt[V[i][j]] >= 2)
                    flag[i][j] = true;
                if(cnt2[V[j][i]] >= 2)
                    flag[j][i] = true;
            }
        }
        rep(i,3){
            rep(j,3){
                //i,j is right up.
                vector<int> cnt(10);
                rep(k,3) rep(l,3){
                    cnt[V[3*i+k][3*j+l]]++;
                }

                rep(k,3) rep(l,3){
                    if(cnt[V[3*i+k][3*j+l]] >= 2){
                        flag[3*i+k][3*j+l] = true;
                    }
                }
            }
        }
        rep(i,9){
            rep(j,9){
                cout << (flag[i][j] ? "*" : " ") << V[i][j];
            }
            cout << endl;
        }
        if(nind != n-1) cout << endl;
    }
    return 0;
}