#include <iostream>
#include <string.h>

using namespace std;
const int N = 9;
void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		char Field[N][N];
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				cin >> Field[i][j];
			}
		}
		bool Flag[N][N];
		memset(Flag, 1, sizeof(Flag));
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				if(Flag[i][j])
				{
					for(int a = 0; a < N; ++a)
					{
						if(i != a && Field[a][j] == Field[i][j])
						{
							Flag[i][j] = Flag[a][j] = false;
						}
					}
					for(int a = 0; a < N; ++a)
					{
						if(j != a && Field[i][a] == Field[i][j])
						{
							Flag[i][j] = Flag[i][a] = false;
						}
					}
					int x = j / 3;
					x *= 3;
					int y = i / 3;
					y *= 3;
					for(int a = x; a < x + 3; ++a)
					{
						for(int b = y; b < y + 3; ++b)
						{
							if(a != j && b != i && Field[b][a] == Field[i][j])
							{
								Flag[b][a] = Flag[i][j] = false;
							}
						}
					}
				}
			}
		}
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				if(Flag[i][j] == false)
				{
					cout << '*';
				}
				else
				{
					cout << ' ';
				}
				cout << Field[i][j];
			}
			cout << endl;
		}
		if(n != 0)
			cout << endl;
	}
}

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