#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		int field[9][9];
		rep(j, 9) rep(k, 9)
			scanf("%d", &field[j][k]);
		
		vector<vector<bool> > collect(9, vector<bool>(9, true));
		rep(j, 3){
			rep(k, 9){
				pii base;
				if(j == 0) base = pii(k, 0);
				if(j == 1) base = pii(0, k);
				if(j == 2) base = pii(k/3*3, k%3*3);
				
				int hist[9] = {0};
				rep(l, 2){
					rep(m, 9){
						pii diff;
						if(j == 0) diff = pii(0, m);
						if(j == 1) diff = pii(m, 0);
						if(j == 2) diff = pii(m/3, m%3);
						
						pii now(base.first + diff.first, base.second + diff.second);
						int a = field[now.first][now.second] - 1;
						if(!l)
							hist[a]++;
						else
							collect[now.first][now.second] = collect[now.first][now.second] & (hist[a] == 1);
					}
				}
			}
		}
		
		if(i)
			puts("");
		rep(j, 9){
			rep(k, 9)
				printf("%c%d", collect[j][k] ? ' ' : '*', field[j][k]);
			puts("");
		}
	}

	return 0;
}