#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
        vector<string> v;
        stringstream ss(str);
        string buffer;
        while (getline(ss, buffer, sep)) {
                v.push_back(buffer);
        }
        return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
        return accumulate(begin, end, 0ll);
}

void solve();

signed main() {
        cout << fixed << setprecision(20);
        solve();
        while(true) {
                char s[MAX];
                if (scanf("%s", s) == EOF) break;
                int n = strlen(s);
                for (int i = n - 1; i > -1; i--) {
                        ungetc(s[i], stdin);
                }
                solve();
        }
        return 0;
}

int t;
int a[10][10];
bool wrong[10][10];

void check1() {
        rep(i, 9) {
                map<int, int> map1;
                rep(j, 9) {
                        map1[a[i][j]]++;
                }
                rep(j, 9) {
                        if (map1[a[i][j]] > 1) {
                                wrong[i][j] = true;
                        }
                }
        }
}

void check2() {
        rep(j, 9) {
                map<int, int> map1;
                rep(i, 9) {
                        map1[a[i][j]]++;
                }
                rep(i, 9) {
                        if (map1[a[i][j]] > 1) {
                                wrong[i][j] = true;
                        }
                }
        }
}

void check3() {
        rep(i, 3) rep(j, 3) {
                map<int, int> map1;
                rep(k, 3) rep(l, 3) {
                        map1[a[3*i + k][3*j + l]]++;
                }
                rep(k, 3) rep(l, 3) {
                        if (map1[a[3*i + k][3*j + l]] > 1) {
                                wrong[3*i + k][3*j + l] = true;
                        }
                }
        }
}

void solve() {
        cin >> t;
        rep(loop, t) {
                rep(i, 9) rep(j, 9) wrong[i][j] = false;
                rep(i, 9) rep(j, 9) cin >> a[i][j];
                check1();
                check2();
                check3();
                rep(i, 9) {
                        rep(j, 9) {
                                cout << (wrong[i][j] ? "*" : " ") << a[i][j];
                        }
                        cout << endl;
                }
                if (loop != t-1) {
                        cout << endl;
                 }
        }
}