#include <iostream>
#include <cstdio>

using namespace std;

int puzzle[10][10];
int col[10][10], row[10][10]; // 列，行
bool check[10][10];  // 間違っている場合はfalse
int n;

/*
  rect[0] rect[1] rect[2]
  rect[3] rect[4] rect[5]
  rect[6] rect[7] rect[8]
*/
int rect[10][10];

void solve()
{
    // 行・列のチェック
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            // 列のチェック
            if (col[j][puzzle[i][j] - 1] != -1) {
                int bf = col[j][puzzle[i][j] - 1];
                check[bf][j] = check[i][j] = false;
                col[j][puzzle[i][j] - 1] = i;
            }
            else
                col[j][puzzle[i][j] - 1] = i;

            // 行のチェック
            if (row[i][puzzle[i][j] - 1] != -1) {
                int bf = row[i][puzzle[i][j] - 1];
                check[i][bf] = check[i][j] = false;
                row[i][puzzle[i][j] - 1] = j;
            }
            else
                row[i][puzzle[i][j] - 1] = j;
        }
    }

    // 3x3の領域のチェック
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                int x = (i % 3) * 3 + k;
                int y = (i / 3) * 3 + j;

                if (rect[i][puzzle[y][x] - 1] != -1) {
                    int nx = (i % 3) * 3 + (rect[i][puzzle[y][x] - 1] % 3);
                    int ny = (i / 3) * 3 + (rect[i][puzzle[y][x] - 1] / 3);

                    check[ny][nx] = check[y][x] = false;
                    rect[i][puzzle[y][x] - 1] = j * 3 + k;
                }
                else
                    rect[i][puzzle[y][x] - 1] = j * 3 + k;                    
            }
        }
    }

    for (int i = 0; i < 9; i++)
        for (int j = 0; j < 9; j++) {
            if (check[i][j]) 
                printf(" %d", puzzle[i][j]);
            else
                printf("*%d", puzzle[i][j]);
            
            if (j + 1 == 9)
                putchar('\n');
        }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 9; j++)
            for (int k = 0; k < 9; k++) {
                cin >> puzzle[j][k];
                col[j][k] = row[j][k] = rect[j][k] = -1;
                check[j][k] = true;
            }

        if (i != 0)
            putchar('\n');
        solve();
    }
        

    return 0;
}