#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

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

int nums[9][9];
bool ok[9][9];

bool check(int y, int x){
	int num = nums[y][x];
	rep(i, 9){
		if(i == y) continue;
		if(nums[i][x] == num) return false;
	}
	rep(i, 9){
		if(i == x) continue;
		if(nums[y][i] == num) return false;
	}
	int by = y / 3;
	int bx = x / 3;
	rep(i, 3){
		rep(j, 3){
			if(by * 3 + i == y && bx * 3 + j == x) continue;
			if(nums[by*3+i][bx*3+j] == num) return false;
		}
	}
	return true;
}

int main(){
	int n;
	cin >> n;
	rep(i, n){
		if(i != 0) cout << endl;
		memset(ok, true, sizeof(ok));
		rep(j, 9)rep(k, 9) cin >> nums[j][k];
		rep(j, 9)rep(k, 9) ok[j][k] = check(j, k);
		rep(j, 9){
			rep(k, 9){
				if(!ok[j][k]) cout << '*';
				else cout << ' ';
				cout << nums[j][k];
			}
			cout << endl;
		}
	}
	return 0;
}