#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>

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

using namespace std;

int main()
{
	int n;
	cin >> n;

	int f[9][9];
	bool flag[9][9];
	map<int,int> ma;
	bool first = true;
	
	while(n--)
	{
		memset(f,0,sizeof(f));

		rep(i,9)
		{
			rep(j,9)
			{
				flag[i][j] = false;
			}
		}

		rep(i,9)
		{
			rep(j,9)
			{
				cin >> f[i][j];
			}
		}

		rep(i,9)
		{
			ma.clear();
			rep(j,9)
			{
				ma[f[i][j]-1]++;
			}

			rep(j,9)
			{
				if(ma[f[i][j]-1] > 1)
				{
					flag[i][j] = true;
				}
			}
		}
		
		
		rep(i,9)
		{
			ma.clear();
			
			rep(j,9)
			{
				ma[f[j][i]-1]++;
			}

			rep(j,9)
			{
				if(ma[f[j][i]-1] > 1)
				{
					flag[j][i] = true;
				}
			}
		}

		int count = 0;
		int x = 0,y = 0;
		while(count != 9)
		{
			ma.clear();
			REP(i,x,x+3)
			{
				REP(j,y,y+3)
				{
					ma[f[i][j]-1]++;
				}
			}

			REP(i,x,x+3)
			{
				REP(j,y,y+3)
				{
					if(ma[f[i][j]-1] > 1)
					{
						flag[i][j] = true;
					}
				}
			}

			if(x+2 == 8)
			{
				if(y+2 == 8)
				{
					break;
				}
				x = 0;
				y += 3;
			}
			else
			{
				x += 3;
			}
		}

		if(first)
		{
			first = false;
		}
		else
		{
			cout << endl;
		}

		rep(i,9)
		{
			rep(j,9)
			{
				if(flag[i][j])
				{
					cout << "*" << f[i][j];
				}
				else
				{
					cout << " " << f[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}