#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

const int MAXW = 9, MAXH = 9;

int tile[MAXW][MAXH];
bool e[MAXW][MAXH];
int c[10];
int dx[] = {0, 3, 6};
int dy[] = {0,3, 6};

int main()
{
    int n;
    cin >> n;
    rep(k,n)
    {
        if(k > 0) cout << endl;
        memset(c, 0, sizeof(c));
        memset(e, false, sizeof(e));
        rep(j,9)rep(i,9) cin >> tile[i][j];

        rep(i,9)
        {
            memset(c, 0, sizeof(c));
            rep(j,9) c[tile[j][i] ] ++;
            rep(j,9)if(c[tile[j][i] ] > 1) e[j][i] = true;

            //vartical
            memset(c, 0, sizeof(c));
            rep(j,9) c[ tile[i][j] ]++;
            rep(j,9) if(c[tile[i][j]] > 1) e[i][j] = true;
        }

        rep(t,3)rep(s,3)
        {
            memset(c, 0, sizeof(c));
            rep(i,3)rep(j,3) c[tile[i + dx[s]][j + dy[t]]]++;
            rep(i,3)rep(j,3)if(c[tile[i + dx[s]][j + dy[t]]] > 1) e[i + dx[s]][j + dy[t]] = true;
        }

        rep(j,9)
        {
            rep(i,9)
            if(e[i][j] ) cout << "*" << tile[i][j];
            else cout << " " << tile[i][j] ;
            
            cout << endl;
        }

    }
    

    return 0;
}