#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int N;
	cin >> N;
	REP(n, N) {
		if (n) puts("");
		
		int maps[9][9];
		bool ans[9][9] = {};
		
		REP(i, 9) REP(j, 9) {
			scanf("%d", &maps[i][j]);
			maps[i][j]--;
		}
		
		REP(i, 3) REP(j, 3) {
			int cnt[9] = {};
			REP(k, 3) REP(l, 3) cnt[maps[i * 3 + k][j * 3 + l]]++;
			REP(k, 3) REP(l, 3) if (cnt[maps[i * 3 + k][j * 3 + l]] > 1)
				ans[i * 3 + k][j * 3 + l] = true;
		}
		
		REP(i, 9) {
			int cnt[9] = {};
			REP(j, 9) cnt[maps[i][j]]++;
			REP(j, 9) if (cnt[maps[i][j]] > 1) ans[i][j] = true;
			
			memset(cnt, 0, sizeof(cnt));
			REP(j, 9) cnt[maps[j][i]]++;
			REP(j, 9) if (cnt[maps[j][i]] > 1) ans[j][i] = true;
		}
		
		REP(i, 9) {
			REP(j, 9) printf("%c%d", ans[i][j] ? '*' : ' ', maps[i][j] + 1);
			puts("");
		}
	}
	
	return 0;
}