#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dx[] = {0,0,0,1,1,1,2,2,2};
int dy[] = {0,1,2,0,1,2,0,1,2};

int main(){
	int N;cin >> N;
	while(N--){
		int data[9][9];
		bool bad[9][9] = {0};
		rep(i,9)rep(j,9)cin >> data[i][j];
		
		rep(i,3)rep(j,3){
			rep(d,9){
				int sx = j*3+dx[d] , sy = i*3+dy[d];
				rep(k,9){
					int tx = j*3+dx[k] , ty = i*3+dy[k];
					if(tx == sx && ty == sy)continue;
					if(data[sy][sx] == data[ty][tx])bad[sy][sx] = true;
				}
			}
		}
		
		rep(i,9){
			rep(j,9){
				rep(k,9){
					if(j == k)continue;
					if(data[i][j] == data[i][k])bad[i][j] = true;
				}
			}
		}
		rep(j,9){
			rep(i,9){
				rep(k,9){
					if(i == k)continue;
					if(data[i][j] == data[k][j])bad[i][j] = true;
				}
			}
		}
		rep(i,9){
			rep(j,9){
				cout << (bad[i][j]?"*":" ") << data[i][j];
			}
			cout << endl;
		}
		if(N)cout << endl;
	}
}