#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	bool bf = false;
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		if (bf) cout << endl;

		int m[9][9];
		for (int y = 0; y < 9; ++y)
			for (int x = 0; x < 9; ++x) {
				cin >> m[y][x];
				--m[y][x];
			}

		bool wa[9][9] = {0};
		for (int y = 0; y < 9; ++y) {
			bool f[9] = {0}, w[9] = {0};
			for (int x = 0; x < 9; ++x)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int x = 0; x < 9; ++x)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int x = 0; x < 9; ++x) {
			bool f[9] = {0}, w[9] = {0};
			for (int y = 0; y < 9; ++y)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int y = 0; y < 9; ++y)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int y = 0; y < 3; ++y)
			for (int x = 0; x < 3; ++x) {
				bool f[9] = {0}, w[9] = {0};
				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy) {
						int nx = x * 3 + dx;
						int ny = y * 3 + dy;

						if (f[m[ny][nx]]) w[m[ny][nx]] = true;
						else f[m[ny][nx]] = true;
					}

				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy) {
						int nx = x * 3 + dx;
						int ny = y * 3 + dy;

						if (w[m[ny][nx]]) wa[ny][nx] = true;
					}
			}

		for (int y = 0; y < 9; ++y) {
			for (int x = 0; x < 9; ++x) {
				if (wa[y][x]) cout << "*";
				else cout << " ";

				cout << (m[y][x] + 1);
			}
			cout << endl;
		}

		bf = true;
	}
}