#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		char field[9][9];
		char isWrong[9][9];
		for(int i = 0; i < 9; ++i)
		{
			for(int j = 0; j < 9; ++j)
			{
				cin >> field[i][j];
				isWrong[i][j] = ' ';
			}
		}
		for(int i = 0; i < 9; ++i)
		{
			vector<int> count(10);
			bool flag = false;
			for(int j = 0; j < 9; ++j)
			{
				++count[field[i][j] - '0'];
				if(count[field[i][j] - '0'] >= 2)
				{
					flag = true;
				}
			}
			if(flag)
			{
				for(int j = 1; j < 10; ++j)
				{
					if(count[j] >= 2)
					{
						for(int k = 0; k < 9; ++k)
						{
							if(field[i][k] == j + '0')
							{
								isWrong[i][k] = '*';
							}
						}
					}
				}
			}
		}
		
		for(int i = 0; i < 9; ++i)
		{
			vector<int> count(10);
			bool flag = false;
			for(int j = 0; j < 9; ++j)
			{
				++count[field[j][i] - '0'];
				if(count[field[j][i] - '0'] >= 2)
				{
					flag = true;
				}
			}
			if(flag)
			{
				for(int j = 1; j < 10; ++j)
				{
					if(count[j] >= 2)
					{
						for(int k = 0; k < 9; ++k)
						{
							if(field[k][i] == j + '0')
							{
								isWrong[k][i] = '*';
							}
						}
					}
				}
			}
		}

		for(int i = 0; i < 3; ++i)
		{
			for(int j = 0; j < 3; ++j)
			{
				int count[10] = {};
				bool flag = false;
				for(int k = 0; k < 3; ++k)
				{
					for(int l = 0; l < 3; ++l)
					{
						++count[field[3 * i + k][3 * j + l] - '0'];
						if(count[field[3 * i + k][3 * j + l] - '0'] >= 2)
						{
							flag = true;
						}
					}
				}
				if(flag)
				{
					for(int k = 1; k < 10; ++k)
					{
						if(count[k] >= 2)
						{
							for(int l = 0; l < 3; ++l)
							{
								for(int m = 0; m < 3; ++m)
								{
									if(field[3 * i + l][3 * j + m] == k + '0')
									{
										isWrong[3 * i + l][3 * j + m] = '*';
									}
								}
							}
						}
					}
				}
			}
		}
		for(int i = 0; i < 9; ++i)
		{
			for(int j = 0; j < 9; ++j)
			{
				cout << isWrong[i][j] << field[i][j];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}