#include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int a[9][9];
		char b[10][10];
		for (int i = 0; i < 9; i++)
		{
			for (int l = 0; l < 9; l++)
			{
				cin >> a[i][l];
				b[i][l] = ' ';
			}
		}

		for (int i = 0; i < 9; i++)
		{
			int h[10] = {};
			for (int l = 0; l < 9; l++)
			{
				h[a[i][l]]++;
			}
			for (int l = 0; l < 9; l++)
			{
				if (h[a[i][l]] != 1)
				{
					b[i][l] = '*';
				}
			}


			int k[10] = {};
			for (int l = 0; l < 9; l++)
			{
				k[a[l][i]]++;
			}
			for (int l = 0; l < 9; l++)
			{
				if (k[a[l][i]] != 1)
				{
					b[l][i] = '*';
				}
			}
		}

		for (int i = 0; i < 9; i += 3)
		{
			for (int l = 0; l < 9; l += 3)
			{
				int h[10] = {};
				for (int j = 0; j < 3; j++)
				{
					for (int u = 0; u < 3; u++)
					{
						h[a[i + j][l + u]]++;
					}
				}

				for (int j = 0; j < 3; j++)
				{
					for (int u = 0; u < 3; u++)
					{
						if (h[a[i + j][l + u]] != 1)
						{
							b[i + j][l + u] = '*';
						}
					}
				}
			}

		}



		for (int i = 0; i < 9; i++)
		{
			for (int l = 0; l < 9; l++)
			{
				cout << b[i][l] << a[i][l];
			}
			cout << endl;
		}
		cout << endl;

	}
}