#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
void solve() {
	int a[10][10];
	bool b[10][10];
	for0(i, 9)for0(j, 9) { cin >> a[i][j]; b[i][j] = 1; }
	int cnt[11];
	for0(i, 9) {
		for1(j, 9)cnt[j] = 0;
		for0(j, 9)cnt[a[i][j]]++;
		for0(j, 9)if (cnt[a[i][j]] > 1)b[i][j] = 0;
	}
	for0(j, 9) {
		for1(i, 9)cnt[i] = 0;
		for0(i, 9)cnt[a[i][j]]++;
		for0(i, 9)if (cnt[a[i][j]] > 1)b[i][j] = 0;
	}
	for0(x, 9) {
		for1(i, 9)cnt[i] = 0;
		for0(y, 9)cnt[a[x / 3 * 3 + y / 3][x % 3 * 3 + y % 3]]++;
		for0(y, 9)if (cnt[a[x / 3 * 3 + y / 3][x % 3 * 3 + y % 3]] > 1)b[x / 3 * 3 + y / 3][x % 3 * 3 + y % 3] = 0;
	}
	for0(i, 9) {
		for0(j, 9)cout << (b[i][j] ? ' ' : '*') << a[i][j];
		cout << endl;
	}
}
signed main() {
	int q; cin >> q; while (q--) { solve(); if (q >= 1)cout << endl; }
}
