#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int ma[9][9];

void solve(int y, int x, int check[][9]){
    rep(i, 9){
        if(ma[i][x] == ma[y][x]) check[i][x]++;
        if(ma[y][i] == ma[y][x]) check[y][i]++;
    }
    rep(i, 3){
        rep(j, 3){
            if(ma[i + y / 3 * 3][j + x / 3 * 3] == ma[y][x])
                check[i + y / 3 * 3][j + x / 3 * 3]++;
        }
    }
}

int main(){
    int n;
    while(cin >> n){
        rep(i, n){
            int check[9][9] = {0};
            rep(i, 9){
                rep(j, 9){
                    cin >> ma[i][j];
                }
            }
            rep(i, 9){
                rep(j, 9){
                    solve(i, j, check);
                }
            }
            rep(i,9){
                rep(j,9){
                    if(check[i][j] > 3)
                        cout << '*';
                    else
                        cout << ' ';
                    cout << ma[i][j];
                }
                cout << endl;
            }
        }
    }
}