#include <bits/stdc++.h>
using namespace std;

int n;
int a[9][9];
bool ok[9][9];

int main() {
    cin >> n;
    for (int iter = 0; iter < n; ++iter) {
        for (int i = 0; i < 9; ++i) for (int j = 0; j < 9; ++j) {
            cin >> a[i][j];
            ok[i][j] = true;
        }
        for (int i1 = 0; i1 < 3; ++i1) for (int j1 = 0; j1 < 3; ++j1) {
            for (int i2 = 0; i2 < 3; ++i2) for (int j2 = 0; j2 < 3; ++j2) {
                int i = i1 * 3 + i2, j = j1 * 3 + j2;
                int num = a[i][j];
                
                // the mass
                for (int i3 = 0; i3 < 3; ++i3) for (int j3 = 0; j3 < 3; ++j3) {
                    int I = i1 * 3 + i3, J = j1 * 3 + j3;
                    if (I == i && J == j) continue;
                    if (a[I][J] == num) {
                        ok[i][j] = false;
                    }
                }
                
                // the row
                for (int J = 0; J < 9; ++J) {
                    if (J == j) continue;
                    if (a[i][J] == num) {
                        ok[i][j] = false;
                    }
                }
                
                // the col
                for (int I = 0; I < 9; ++I) {
                    if (I == i) continue;
                    if (a[I][j] == num) {
                        ok[i][j] = false;
                    }
                }
            }
        }
        
        for (int i = 0; i < 9; ++i) {
            for (int j = 0; j < 9; ++j) {
                cout << (ok[i][j] ? ' ' : '*');
                cout << a[i][j];
            }
            cout << endl;
        }
        if (iter != n-1) cout << endl;
    }
}
