#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    cin >> n;
    rep(q, n){
        vii v; vbb b;
        rep(i, 9){
            vi r; vb l;
            rep(j, 9){
                int m; cin >> m; r.pb(m); l.pb(true);
            }
            v.pb(r); b.pb(l);
        }
        rep(i, 9){
            pair<bool, pair<int, int> > p[11];
            rep(j, 11) p[i].first = false;
            rep(j, 9){
                if(!p[v[i][j]].first){p[v[i][j]].first = true; p[v[i][j]].second = mp(i, j);}
                else {b[i][j] = false; pii x = p[v[i][j]].second; b[x.first][x.second] = false;}
            }
        }
        rep(i, 9){
            pair<bool, pair<int, int> > p[11];
            rep(j, 11) p[j].first = false;
            rep(j, 9){
                if(!p[v[j][i]].first){p[v[j][i]].first = true; p[v[j][i]].second = mp(j, i);}
                else {b[j][i] = false; pii x = p[v[j][i]].second; b[x.first][x.second] = false;}
            }
        }
        rep(i, 3)rep(j, 3){
            pair<bool, pair<int, int> > p[11];
            rep(l, 11) p[l].first = false;
            rep(k, 3)rep(l, 3){
                if(!p[v[i*3+k][j*3+l]].first){p[v[i*3+k][j*3+l]].first = true; p[v[i*3+k][j*3+l]].second = mp(i*3+k, j*3+l);}
                else {b[i*3+k][j*3+l] = false; pii x = p[v[i*3+k][j*3+l]].second; b[x.first][x.second] = false;  }
            }
        }

        rep(i, 9){
            rep(j, 9){
                cout << (b[i][j]?" ":"*") << v[i][j];
            }
            cout << endl;
        }
        if(q != n-1) cout << endl;
    }
}