#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N;
	cin >> N;
	while (N--) {
		int field[9][9];
		for (int i = 0; i < 9; ++i) {
			for (int j = 0; j < 9; ++j) {
				cin >> field[i][j];
			}
		}
		vector<vector<int>>oks(9, vector<int>(9,true));
		for (int i = 0; i < 9; ++i) {
			for (int j = 0; j < 9; ++j) {
				for (int k = 0; k < 9; ++k) {
					if (j == k)continue;
					if (field[i][j] == field[i][k])oks[i][j] = false;
				}
				for (int k = 0; k < 9; ++k) {
					if (i == k)continue;
					if (field[i][j] == field[k][j])oks[i][j] = false;
				}
				int ax = j / 3;
				int ay = i / 3;
				for (int k = ax * 3; k < ax * 3 + 3; ++k) {
					for (int l = ay * 3; l < ay * 3 + 3; ++l) {
						if (k == j&&l == i)continue;
						if (field[i][j] == field[l][k])oks[i][j] = false;
					}
				}
			}
		}
		for (int i = 0; i < 9; ++i) {
			for (int j = 0; j < 9; ++j) {
				if (oks[i][j])cout << " ";
				else cout << "*";
				cout << field[i][j];
			}
			cout << endl;
		}
		if(N)cout << endl;
		
	}
	return 0;
}