#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-8
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;

int main(){
	int N;
	scanf("%d",&N);
	const int hoge = N;
	rep(n,hoge){
		int field[10][10];
		bool fail[10][10]={{0}};
		rep(i,9){
			rep(j,9){
				scanf("%d",&field[i][j]);
			}
		}
		//よこ
		rep(i,9){
			int cnt[10]={0};
			rep(j,9){
				cnt[field[i][j]]++;
			}
			rep(j,10){
				if(cnt[j]>1){
					rep(k,9){
						if(field[i][k]==j)fail[i][k]=1;
					}
				}
			}
		}
		//たて
		rep(i,9){
			int cnt[10]={0};
			rep(j,9){
				cnt[field[j][i]]++;
			}
			rep(j,10){
				if(cnt[j]>1){
					rep(k,9){
						if(field[k][i]==j)fail[k][i]=1;
					}
				}
			}
		}
		//わく
		for(int i = 0; i < 9;i+=3){
			for(int j = 0; j < 9; j+=3){
				int cnt[10]={0};
				reps(k,i,i+3){
					reps(l,j,j+3){
						cnt[field[k][l]]++;
					}
				}
				rep(m,10){
					if(cnt[m]>1){
						reps(k,i,i+3){
							reps(l,j,j+3){
								if(field[k][l] == m)fail[k][l]=1;
							}
						}
					}
				}
			}
		}
		rep(i,9){
			rep(j,9){
				printf("%c%d",fail[i][j]==1?'*':' ',field[i][j]);
			}
			puts("");
		}
		n == hoge-1?printf(""):puts("");
	}
	return 0;
}