#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,m[9][9],f[9][9];

int main(){
	cin>>n;
	while(n--){
		memset(f,0,sizeof(f));
		rep(i,9)rep(j,9)cin>>m[i][j];
		rep(i,9){
			rep(j,9)rep2(k,j+1,9){
				if(m[i][j]==m[i][k])f[i][j]=f[i][k]=1;
				if(m[j][i]==m[k][i])f[j][i]=f[k][i]=1;
			}
		}
		rep(i,3)rep(j,3){
			rep(ii,3)rep(jj,3)rep(iii,3)rep(jjj,3){
				if((ii!=iii||jj!=jjj)&&m[i*3+ii][j*3+jj]==m[i*3+iii][j*3+jjj]){
					f[i*3+ii][j*3+jj]=f[i*3+iii][j*3+jjj]=1;
				}
			}
		}
		rep(i,9){
			rep(j,9)cout<<(f[i][j]?"*":" ")<<m[i][j];
			cout<<endl;
		}
		if(n)cout<<endl;
	}
}