#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
#include<unordered_map>
#include<map>
#include<vector>
#define P pair<int,int>
using namespace std;

int main()
{
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		if (b)cout << endl;
		bool k[9][9]{};
		int c[9][9];
		for (int d = 0; d < 9; d++) {
			for (int e = 0; e < 9; e++) {
				cin >> c[d][e];
			}
		}
		for (int f = 0; f < 9; f++) {
			vector<P>h[10];
			for (int g = 0; g < 9; g++) {
				h[c[f][g]].push_back(P(f, g));
			}
			for (auto i : h) {
				if (i.size() > 1) {
					for (P j : i) {
						k[j.first][j.second] = true;
					}
				}
			}
		}
		for (int f = 0; f < 9; f++) {
			vector<P>h[10];
			for (int g = 0; g < 9; g++) {
				h[c[g][f]].push_back(P(g, f));
			}
			for (auto i : h) {
				if (i.size() > 1) {
					for (P j : i) {
						k[j.first][j.second] = true;
					}
				}
			}
		}
		for (int f = 0; f < 3; f++) {
			for (int g = 0; g < 3; g++) {
				vector<P>h[10];
				for (int k = 0; k < 3; k++) {
					for (int l = 0; l < 3; l++) {
						h[c[f * 3 + k][g * 3 + l]].push_back(P(f*3+k,g*3+l));
					}
				}
				for (auto i : h) {
					if (i.size() > 1) {
						for (P j : i) {
							k[j.first][j.second] = true;
						}
					}
				}
			}
		}
		for (int x = 0; x < 9; x++) {
			for (int y = 0; y < 9; y++) {
				if (k[x][y])cout << '*';
				else cout << ' ';
				cout << c[x][y];
			}
			cout << endl;
		}
	}
}