#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int dataset;
	cin >> dataset;
	bool f = true;
	while(dataset--){
		if(!f) cout << endl;

		vector<vi> v(9, vi(9, 0));
		vector<vi> ng = v;
		rep(i, 9) rep(j, 9) cin >> v[i][j];

		rep(i, 9){
			vi cnt1(10, 0), cnt2(10, 0), cnt3(10, 0);
			int x = i%3*3;
			int y = i/3*3;
			rep(j, 9){
				cnt1[v[i][j]]++;
				cnt2[v[j][i]]++;
				cnt3[v[y+j/3][x+j%3]]++;
			}
			rep(j, 9){
				if((cnt1[v[i][j]] >= 2)) ng[i][j] = 1;
				if(cnt2[v[j][i]] >= 2) ng[j][i] = 1;
				if((cnt3[v[y+j/3][x+j%3]] >= 2)) ng[y+j/3][x+j%3] = 1;
			}
		}

		rep(i, 9){
			rep(j, 9){
				cout << (ng[i][j]?'*':' ') << v[i][j];
			}
			cout << endl;
		}

		f = false;
	}


	return 0;
}