#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int SIZE = 9;
int T[SIZE][SIZE];
bool F[SIZE][SIZE];

void input() {
    for ( int i = 0; i < SIZE; ++ i ) {
        for ( int j = 0; j < SIZE; ++ j ) {
            cin >> T[i][j];
        }
    }
}

bool check( int r, int c ) {
    int sr = r - r % 3;
    int sc = c - c % 3;
    for ( int i = 0; i < SIZE; ++ i ) {
        if ( i != c && T[r][c] == T[r][i] ) return true;
        if ( i != r && T[r][c] == T[i][c] ) return true;
    }
    for ( int i = 0; i < 3; ++ i ) {
        for ( int j = 0; j < 3; ++ j ) {
            if ( sr + i == r && sc + j == c ) continue;
            if ( T[r][c] == T[sr+i][sc+j] ) return true;
        }
    }
    return false;
}

void solve() {
    fill( (bool*)F, (bool*)F+SIZE*SIZE, false );
    for ( int i = 0; i < SIZE; ++ i ) {
        for ( int j = 0; j < SIZE; ++ j ) {
            F[i][j] = check( i, j );
        }
    }
    for ( int i = 0; i < SIZE; ++ i ) {
        for ( int j = 0; j < SIZE; ++ j ) {
            cout << ( F[i][j] ? '*' : ' ' ) << T[i][j];
        }
        cout << endl;
    }
}

int main() {
    int n;
    while ( cin >> n ) {
        for ( int i = 0; i < n; ++ i ) {
            input();
            solve();
            if ( i + 1 < n ) cout << endl;
        }
    }
    return 0;
}