#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int n;
int masu[9][9];
bool wrong[9][9];

int main()
{
	cin >> n;

	while (n--)
	{
		memset(wrong, 0, sizeof(wrong));

		rep(i, 9) rep(j, 9)	cin >> masu[i][j];
	
		//横
		rep(i, 9) rep(j, 9) rep(k, 9)
		{
			if (masu[i][j] == masu[i][k] && j != k) wrong[i][j] = wrong[i][k] = true;
		}

		//縦
		rep(i, 9) rep(j, 9) rep(k, 9)
		{
			if (masu[j][i] == masu[k][i] && j != k) wrong[j][i] = wrong[k][i] = true;
		}

		//ブロック
		for (int i=0; i<9; i+=3)
		{
			for (int j=0; j<9; j+=3)
			{
				for (int k=i; k<i+3; k++)
				{
					for (int l=j; l<j+3; l++)
					{
						for (int m=i; m<i+3; m++)
						{
							for (int n=j; n<j+3; n++)
							{
								if (masu[k][l] == masu[m][n] && k != m && l != n)
								{
									wrong[k][l] = wrong[m][n] = true;
								}
							}
						}
					}
				}
			}
		}

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

		if (n != 0) cout << endl;
	}
	
	return 0;
}