#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(--n >= 0){
        vector<vector<int> > a(9, vector<int>(9));
        for(int i=0; i<9; ++i){
            for(int j=0; j<9; ++j){
                cin >> a[i][j];
            }
        }

        vector<vector<bool> > wrong(9, vector<bool>(9, false));
        for(int i=0; i<9; ++i){
            for(int j=0; j<9; ++j){
                for(int k=j+1; k<9; ++k){
                    if(a[i][j] == a[i][k])
                        wrong[i][j] = wrong[i][k] = true;
                    if(a[j][i] == a[k][i])
                        wrong[j][i] = wrong[k][i] = true;
                    int y1 = (i/3)*3 + (j/3);
                    int x1 = (i%3)*3 + (j%3);
                    int y2 = (i/3)*3 + (k/3);
                    int x2 = (i%3)*3 + (k%3);
                    if(a[y1][x1] == a[y2][x2])
                        wrong[y1][x1] = wrong[y2][x2] = true;
                }
            }
        }

        for(int i=0; i<9; ++i){
            for(int j=0; j<9; ++j){
                if(wrong[i][j])
                    cout << '*';
                else
                    cout << ' ';
                cout << a[i][j];
            }
            cout << endl;
        }

        if(n > 0)
            cout << endl;
    }
}