#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, t[10][10];

int main(){
	cin >> n;
	bool g = 0;
	REP(i, n){
		if (g)cout << endl;
		REP(i, 9)REP(j, 9)cin >> t[i][j];
		REP(i, 9){
			REP(j, 9){
				bool f = 0;
				REP(k, 9){
					if (j == k)continue;
					if (t[i][k] == t[i][j])f = 1;
				}
				REP(k, 9){
					if (i == k)continue;
					if (t[k][j] == t[i][j])f = 1;
				}
				//cout << endl;
				REP(k, 3){
					REP(l, 3){
						//cout << i / 3 * 3 + k << " " << j / 3 * 3 + l << endl;
						if (i / 3 * 3 + k == i&&j / 3 * 3 + l == j)continue;
						if (t[i / 3 * 3 + k][j / 3 * 3 + l] == t[i][j])f = 1;
					}
				}
				f ? cout << "*" : cout << " ";
				cout << t[i][j];
			}
			cout << endl;
		}
		g = 1;
	}
}