#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int d[9][9];
bool f[9][9];

vector<pii> v(9);

void input(){
	rep(i, 9) rep(j, 9) cin>>d[i][j], f[i][j] = false;
}
void output(){
	for(int i = 0; i < 9; i++){
		for(int j = 0; j < 9; j++){
			printf("%c%d", f[i][j]?'*':' ', d[i][j]);
		}
		printf("\n");
	}
}
void calc(){
	for(int i = 0; i < 8; i++){
		for(int j = i + 1; j < 9; j++){
			if(v[i].fi == v[j].fi){
				f[v[i].se/10][v[i].se%10] = true;
				f[v[j].se/10][v[j].se%10] = true;
			}
		}
	}
}

int main(){
	int n;
	cin>>n;
	rep(Case, n){
		if(Case != 0) printf("\n");
		input();
		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				v[j] = mp(d[i][j], i*10+j);
			}
			calc();
		}
		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 9; j++){
				v[j] = mp(d[j][i], j*10+i);
			}
			calc();
		}
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 3; k++){
					for(int l = 0; l < 3; l++){
						int y = i * 3 + k, x = j * 3 + l, idx = k * 3 + l;
						v[idx] = mp(d[y][x], y* 10 + x);
					}
				}
				calc();
			}
		}
		output();
	}
}