#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	int m[9][9];
	bool b[9][9] = {};
	bool first = true;
	rep(h, 0, n) {
		if (!first)cout << endl;
		first = false;
		rep(i, 0, 9)rep(j, 0, 9)cin >> m[i][j];

		rep(i, 0, 9) {
			int cnt[10] = {};
			rep(j, 0, 9)cnt[m[i][j]]++;
			rep(j, 0, 9) {
				if (cnt[m[i][j]] >= 2)b[i][j] = true;
			}
		}
		rep(j, 0, 9) {
			int cnt[10] = {};
			rep(i, 0, 9)cnt[m[i][j]]++;
			rep(i, 0, 9) {
				if (cnt[m[i][j]] >= 2)b[i][j] = true;
			}
		}
		for (int i = 0; i < 9; i += 3) {
			for (int j = 0; j < 9; j += 3) {
				int cnt[10] = {};
				rep(I, i, i + 3)rep(J, j, j + 3) {
					cnt[m[I][J]]++;
				}
				rep(I, i, i + 3)rep(J, j, j + 3) {
					if (cnt[m[I][J]] >= 2)b[I][J] = true;
				}
			}
		}
		rep(i, 0, 9) {
			rep(j, 0, 9) {
				if (b[i][j])cout << "*";
				else cout << " ";
				cout << m[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}