#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n; scanf("%d%*c", &n);
	rep(I, n) {
		string s[9];
		rep(i, 9) {
			getline(cin, s[i]);
			s[i] = ' ' + s[i];
		}
		rep(i, 9) {
			int cnt[9]{};
			for (int j = 1; j < s[i].size(); j += 2)
				cnt[s[i][j] - '1']++;
			for (int j = 0; j < s[i].size(); j += 2) {
				if (cnt[s[i][j + 1] - '1'] > 1)s[i][j] = '*';
			}
		}
		for (int i = 1; i < s[0].size(); i += 2) {
			int cnt[9]{};
			rep(j, 9)
				cnt[s[j][i] - '1']++;
			rep(j, 9) {
				if (cnt[s[j][i] - '1'] > 1)s[j][i - 1] = '*';
			}
		}
		for (int i = 1; i < s[0].size(); i += 6) {
			for (int j = 0; j < 9; j += 3) {
				int cnt[9]{};
				rep(t, 3)for (int k = 0; k < 6; k += 2) {
					cnt[s[j + t][i + k] - '1']++;
				}
				rep(t, 3)for (int k = 0; k < 6; k += 2) {
					if (cnt[s[j + t][i + k] - '1'] > 1) {
						s[j + t][i + k - 1] = '*';
					}
				}
			}
		}
		rep(i, 9) {
			cout << s[i] << endl;
		}
		if (I != n - 1)cout << endl;
	}
}