#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int t = 0; t < n; t++) {
        int a[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                cin >> a[i][j];
            }
        }
        bool flag[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                flag[i][j] = false;
            }
        }
        for (int i = 1; i < 10; i++) {
            for (int j = 0; j < 9; j++) {
                int count = 0;
                for (int k = 0; k < 9; k++) {
                    if (a[j][k] == i) count++;
                }
                if (count <= 1) continue;
                for (int k = 0; k < 9; k++) {
                    if (a[j][k] == i) flag[j][k] = true;
                }
            }


            for (int j = 0; j < 9; j++) {
                int count = 0;
                for (int k = 0; k < 9; k++) {
                    if (a[k][j] == i) count++;
                }
                if (count <= 1) continue;
                for (int k = 0; k < 9; k++) {
                    if (a[k][j] == i) flag[k][j] = true;
                }
            }

            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    int count = 0;
                    for (int l = 0; l < 3; l++) {
                        for (int o = 0; o < 3; o++) {
                            if (a[j * 3 + l][k * 3 + o] == i) count++;
                        }
                    }
                    if (count <= 1) continue;
                    for (int l = 0; l < 3; l++) {
                        for (int o = 0; o < 3; o++) {
                            if (a[j * 3 + l][k * 3 + o] == i) {
                                flag[j * 3 + l][k * 3 + o] = true;
                            }
                        }
                    }
                }
            }
        }

        if (t) cout << endl;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (flag[i][j]) cout << "*";
                else cout << " ";
                cout << a[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}