#include <iostream>
using namespace std;

bool isRuledCell(int x, int y, int field[9][9]) {
    for (int nx = 0; nx < 9; nx++) {
        if (x != nx && field[y][x] == field[y][nx]) {
            return false;
        }
    }
    for (int ny = 0; ny < 9; ny++) {
        if (y != ny && field[y][x] == field[ny][x]) {
            return false;
        }
    }
    for (int ny = y - (y % 3), endy = ny + 2; ny <= endy; ny++) {
        for (int nx = x - (x % 3), endx = nx + 2; nx <= endx; nx++) {
            if (y != ny && x != nx && field[y][x] == field[ny][nx]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    bool newLineFlag = false;
    for (int i = 0; i < n; i++) {
        if (newLineFlag) {
            cout << endl;
        } else {
            newLineFlag = true;
        }
        int field[9][9];
        for (int j = 0; j < 9; j++) {
            for (int k = 0; k < 9; k++) {
                cin >> field[j][k];
            }
        }
        for (int j = 0; j < 9; j++) {
            for (int k = 0; k < 9; k++) {
                if (isRuledCell(k, j, field)) {
                    cout << " " << field[j][k];
                } else {
                    cout << "*" << field[j][k];
                }
            }
            cout << endl;
        }
    }
}