#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

int puzzle[9][9];
bool ast[9][9];

void check() {
    for (int i=0; i<9; ++i) {
        for (int j=0; j<9; ++j) {
            for (int k=0; k<9; ++k) {
                if (i != k && puzzle[i][j] == puzzle[k][j]) {
                    ast[i][j] = true;
                    break;
                }
                if (j != k && puzzle[i][j] == puzzle[i][k]) {
                    ast[i][j] = true;
                    break;
                }
            }
            for (int k=(i/3)*3; k<(i/3)*3+3; ++k) {
                for (int l=(j/3)*3; l<(j/3)*3+3; ++l) {
                    if ((i != k || j != l) && puzzle[i][j] == puzzle[k][l]) {
                        ast[i][j] = true;
                        break;
                    }
                }
            }
        }
    }
}

int main() {
    int n;
    bool lf = false;
    cin >> n;
    for (int k=0; k<n; ++k) {
        if (lf) {
            cout << endl;
        }
        memset(ast, false, sizeof ast);
        for (int i=0; i<9; ++i) {
            for (int j=0; j<9; ++j) {
                cin >> puzzle[i][j];
            }
        }
        check();
        for (int i=0; i<9; ++i) {
            for (int j=0; j<9; ++j) {
                cout << (ast[i][j] ? "*" : " ") << puzzle[i][j];
            }
            cout << endl;
        }
        lf = true;
    }
    return 0;
}