#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool ok[9][9];
int m[9][9];

void reset(int *r){
	for(int i = 0; i < 10; ++i)
		*(r + i) = 0;
}

void func(int x, int y){
	int cn[10] = {};
	for(int i = x; i < x + 3; ++i)
		for(int j = y; j < y + 3; ++j)
			cn[m[i][j]]++;
			
	for(int i = x; i < x + 3; ++i){
		for(int j = y; j < y + 3; ++j){
			if(cn[m[i][j]] >= 2)
				ok[i][j] = true;
		}
	}
}
int main() {
	int n;
	cin >> n;
	for(int c = 0; c < n; ++c){
		for(int i = 0; i < 9; ++i)
			for(int j = 0; j < 9; ++j)
				ok[i][j] = false;
			
		for(int i = 0; i < 9; ++i)
			for(int j = 0; j < 9; ++j)
				cin >> m[i][j];
		
		int cnt[10] = {0};
		for(int i = 0; i < 9; ++i){
			for(int j = 0; j < 9; ++j)
				cnt[m[j][i]]++;
				
			for(int j = 0; j < 9; ++j){
			if(cnt[m[j][i]] >= 2)
				ok[j][i] = true;
			}
			reset(cnt);
		}
	
		for(int i = 0; i < 9; ++i){
			for(int j = 0; j < 9; ++j)
				cnt[m[i][j]]++;
				
			for(int j = 0; j < 9; ++j){
				if(cnt[m[i][j]] >= 2)
					ok[i][j] = true;
			}
			reset(cnt);
		}
		
		for(int i = 0; i < 9; i += 3)
			for(int j = 0; j < 9; j += 3)
				func(i, j);
				
		for(int i = 0; i < 9; ++i){
			for(int j = 0; j < 9; ++j){
				if(ok[i][j])
					cout << "*";
				else
					cout << " ";
				cout << m[i][j];
			}
			cout << endl;
		}
		if(c != n - 1)
			cout << endl;
	}
	return 0;
}