#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>

using namespace std;

int board[9][9];

bool Solution(int x, int y)
{
    int count = 0;
    
    for (int i = 0; i < 9; i++)
    {
        if (board[x][i] == board[x][y])
        {
            count++;
        }
        
        if (board[i][y] == board[x][y])
        {
            count++;
        }
    }
    
    int devideX = x / 3;
    int devideY = y / 3;
    
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (board[devideX * 3 + i][devideY * 3 + j] == board[x][y])
            {
                count++;
            }
        }
    }
    
    return count == 3;
}

int main()
{
    int n;
 
    bool flag = true;
    
    cin>>n;
    
    while(n--)
    {
        if (flag)
        {
            flag = false;
        }
        else
        {
            cout << endl;
        }
        
        for (int j = 0; j < 9; j++)
        {
            for (int k = 0; k < 9; k++)
            {
                cin>>board[j][k];
            }
        }
        
        for (int j = 0; j < 9; j++)
        {
            for (int k = 0; k < 9; k++)
            {
                char c = ' ';
                
                if (!Solution(j, k))
                {
                    c = '*';
                }
                
                cout << c << board[j][k];
            }
            
            cout << endl;
        }
    }
    
    return 0;
}