# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
# include <unordered_map>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	int n; cin >> n;
	bool f = false;
	while (n--)
	{
		if (f)cout << endl;
		f = true;
		int a[9][9];
		bool b[9][9];
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{
				cin >> a[i][j];
				b[i][j] = false;
			}
		}
		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{


				for (int k = 0; k < 9; k++)
				{
					if (k == j)continue;
					if (a[i][j] == a[i][k])
					{
						b[i][j] = true;
						b[i][k] = true;
					}
					if (a[j][i] == a[k][i])
					{
						b[j][i] = true;
						b[k][i] = true;
					}
				}
				if (i % 3 == 0 && j % 3 == 0)
				{
					for (int k = 0; k < 9; k++)
					{
						for (int l = 0; l < 9; l++)
						{
							if (i + k % 3 == i + l % 3 || j + k / 3 == j + l / 3)continue;
							if (a[i + k % 3][j + k / 3] == a[i + l % 3][j + l / 3])
							{
								b[i + k % 3][j + k / 3] = true;
								b[i + l % 3][j + l / 3] = true;
							}
						}
					}
				}

			}
		}

		for (int i = 0; i < 9; i++)
		{
			for (int j = 0; j < 9; j++)
			{
				cout << (b[i][j] ? '*' : ' ');
				cout << a[i][j];
			}
			cout << endl;
		}
	}


}