#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int field[10][10], used[10];
	bool judge[10][10];

	int num;
	cin >> num;
	while(num--)
	{
		memset(judge, false, sizeof(judge));

		for(int i = 0; i < 9; i++)
		{
			for(int j = 0; j< 9; j++)
			{
				cin >> field[i][j];
			}
		}
		for(int i = 0; i < 9; i++)
		{
			memset(used, 0, sizeof(used));
			for(int j = 0; j < 9; j++)
			{
				used[field[i][j]]++;
			}
			for(int j = 1; j <=9; j++)
			{
				if(used[j] >= 2)
				{
					for(int k = 0; k < 9; k++)
					{
						if(field[i][k] == j)
						{
							judge[i][k] = true;
						}
					}
				}
			}
			memset(used, 0, sizeof(used));
			for(int j = 0; j < 9; j++)
			{
				used[field[j][i]]++;
			}
			for(int j = 1; j<= 9; j++)
			{
				//printf("%d%s",used[j] ,(j == 9)?"\n":" ");
				if(used[j] >= 2)
				{
					for(int k = 0; k < 9; k++)
					{
						if(field[k][i] == j)
						{
							judge[k][i] = true;
						}
					}
				}
			}
		}

		for(int l = 0; l < 9; l+=3)
		{
			for(int m = 0; m < 9; m+=3)
			{
				memset(used, false, sizeof(used));
				for(int i = 0; i < 3; i++)
				{
					for(int j = 0; j < 3; j++)
					{
						used[field[i+l][j+m]]++;
					}
				}

				for(int n = 1; n <=9; n++)
				{
					if(used[n] >= 2)
					{
						for(int i = 0; i < 3; i++)
						{
							for(int j = 0; j < 3; j++)
							{
								if(field[i+l][j+m] == n)
								{
									judge[i+l][j+m] = true;
								}
							}
						}
					}
				}
			}
		}

		for(int i = 0; i < 9; i++)
		{
			for(int j = 0; j < 9; j++)
			{
				printf("%s%d",(judge[i][j])?"*":" " ,field[i][j]);
			}
			puts("");
		}
		if(num != 0)
		{
			puts("");
		}
	}
}