#include<iostream>
using namespace std;

void checkA( char a[9][18] )
{
    int b[10];
    
    for( int i = 0; i < 9; i++ )
    {
        for( int j = 0; j < 10; j++ )
            b[j] = 0;
        for( int j = 1; j < 18;  j += 2 )
            b[a[i][j]-'0']++;
        for( int j = 1; j < 18;  j += 2 )
            if( b[a[i][j]-'0'] >= 2 )
                a[i][j-1] = '*';
    }
}

void checkB( char a[9][18] )
{
    int b[10];
    
    for( int i = 1; i < 18; i += 2 )
    {
        for( int j = 0; j < 10; j++ )
            b[j] = 0;
        for( int j = 0; j < 9; j++ )
            b[a[j][i]-'0']++;
        for( int j = 0; j < 9; j++ )
            if( b[a[j][i]-'0'] >= 2 )
                a[j][i-1] = '*';
    }
}

void checkC2( char a[9][18], int x, int y, int w, int z )
{
    int b[10];

    for( int j = 0; j < 10; j++ )
        b[j] = 0;

    for( int i = x; i <= w; i++ )
        for( int j = y; j <= z; j += 2 )
            b[a[i][j]-'0']++;

    for( int i = x; i <= w; i++ )
        for( int j = y; j <= z; j += 2 )
            if( b[a[i][j]-'0'] >= 2 )
                a[i][j-1] = '*';
}

void checkC1( char a[9][18] )
{
    checkC2( a, 0, 1, 2, 5 );
    checkC2( a, 0, 7, 2, 11 );
    checkC2( a, 0, 13, 2, 17 );
    checkC2( a, 3, 1, 5, 5 );
    checkC2( a, 3, 7, 5, 11 );
    checkC2( a, 3, 13, 5, 17);
    checkC2( a, 6, 1, 8, 5 );
    checkC2( a, 6, 7, 8, 11 );
    checkC2( a, 6, 13, 8, 17 );
}

int main()
{
    int n;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        if( i != 0 )
            cout << endl;

        char a[9][18];
        for( int j = 0; j < 9; j++ )
        {
            for( int k = 0; k < 18; k++ )
            {
                if( k % 2 == 0 )
                    a[j][k] = ' ';
                else
                    cin >> a[j][k];
            }
        }

        checkA( a );
        checkB( a );
        checkC1( a );

        for( int j = 0; j < 9; j++ )
        {
            for( int k = 0; k < 18; k++ )
                cout << a[j][k];
            cout << endl;
        }

    }

    return 0;
}
