#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int sudoku[10][10];

bool ok(int a,int b){
	int i,j;
	for(i=0;i<9;i++){
		if(i!=a&&sudoku[a][b]==sudoku[i][b])return false;
	}
	for(i=0;i<9;i++){
		if(i!=b&&sudoku[a][b]==sudoku[a][i])return false;
	}
	for(i=a/3*3;i<a/3*3+3;i++){
		for(j=b/3*3;j<b/3*3+3;j++){
			if(i!=a&&j!=b&&sudoku[a][b]==sudoku[i][j])return false;
		}
	}
	return true;
}

int main() {
	int n=in();
	int i;
	for(i=0;i<n;i++){
		if(i>0)cout<<endl;
		int a,b;
		for(a=0;a<9;a++){
			for(b=0;b<9;b++){
				cin>>sudoku[a][b];
			}
		}
		for(a=0;a<9;a++){
			for(b=0;b<9;b++){
				if(ok(a,b)){
					cout<<" "<<sudoku[a][b];
				}else{
					cout<<"*"<<sudoku[a][b];
				}
			}
			cout<<endl;
		}
	}
	return 0;
}