#include <iostream>
using namespace std;
int field[9][9];

bool check(int x, int y) {
	int count = 0;
	for (int i = 0; i < 9; i++) {
		if (field[x][i] == field[x][y]) count++;
		if (field[i][y] == field[x][y]) count++;
	}
	int ofx = x / 3;
	int ofy = y / 3;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (field[ofx * 3 + i][ofy * 3 + j] == field[x][y]) count++;
		}
	}
	return count == 3;
}

int main() {
	int n;
	bool flg = true;
	cin >> n;
	for (int i = 0; i < n ; i++) {
		if (flg) {
			flg = false;
		}
		else {
			cout << endl;
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				cin >> field[j][k];
			}
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				char c = ' ';
				if (!check(j, k)) {
					c = '*';
				}
				cout << c << field[j][k];
			}
			cout << endl;
		}
	}
}