#include <cstdio>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
int a[9][9],b[9][9],c[10],n;
int main()
{
    scanf("%d", &n);
    while (n--) {
        rep(i, 9) rep(j, 9) b[i][j] = 0;
        rep(i, 9) rep(j, 9) scanf("%d", &a[i][j]);
        rep(i, 9) rep(j, 9) rep(k, 9) {
            if (j == k) continue;
            if (a[i][j] == a[i][k]) b[i][j] = b[i][k] = 1;
        }
        rep(i, 9) rep(j, 9) rep(k, 9) {
            if (i == k) continue;
            if (a[i][j] == a[k][j]) b[i][j] = b[k][j] = 1;
        }
        for (int i = 0; i < 9; i += 3) {
            for (int j = 0; j < 9; j += 3) {
                rep(k, 10) c[k] = 0;
                rep(k, 3) rep(l, 3) c[a[i+k][j+l]]++;
                rep(k, 3) rep(l, 3) if (c[a[i+k][j+l]] > 1) b[i+k][j+l] = 1;
            }
        }

        rep(i, 9) {
            rep(j, 9) { putchar(b[i][j] ? '*' : ' '); printf("%d", a[i][j]); }
            puts("");
        }
        if (n > 0) puts("");
    }
    return 0;
}