#include <iostream>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool ok[9][9] = {};
void check(int *a, int x, bool f) {
	int c[9] = {};
	rep(i,9) c[a[i]-1]++;
	rep(i,9) {
		if(c[a[i]-1] != 1) {
			if(f) ok[x][i] = 1;
			else ok[i][x] = 1;
		}
	}
}
int main() {
	int n;
	cin >> n;
	bool p = 0;
	while(n--) {
		if(p) cout << endl;
		p = 1;
		int b[9][9];
		rep(i,9) {
			rep(j,9) {
				ok[i][j] = 0;
				cin >> b[i][j];
			}
		}
		rep(i,9) {
			int a[9];
			rep(j,9) {
				a[j] = b[i][j];
			}
			check(a,i,1);	
		}
		rep(i,9) {
			int a[9];
			rep(j,9) {
				a[j] = b[j][i];
			}
			check(a,i,0);	
		}
		rep(w,9) {
			if(w%3!=0) continue;
			rep(h,9) {
				if(h%3!=0) continue;
				int c[9]={};
				rep(i,3) {
					rep(j,3) {
						c[b[w+i][h+j]-1]++;
					}
				}
				rep(i,3) {
					rep(j,3) {
						if(c[b[w+i][h+j]-1] != 1) ok[w+i][h+j] = 1;
					}
				}
			}
		}
		rep(i,9) {
			string ret;
			rep(j,9) {
				if(ok[i][j]) ret += '*';
				else ret += ' ';
				ret += (char)(b[i][j]+'0');
			}
			cout << ret << endl;
		}
	}
	return 0;
}