#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int puzzle[9][9];
		for (int i = 0; i < 9; ++i)
		{
			for (int j = 0; j < 9; ++j)
			{
				int t;
				scanf("%d", &t);
				puzzle[i][j] = t;
			}
		}

		bool dame[9][9];
		memset(dame, 0, sizeof(dame));
		for (int i = 0; i < 9; ++i)
		{
			vector<pair<int, int> > v[10];
			vector<pair<int, int> > h[10];
			for (int j = 0; j < 9; ++j)
			{
				v[puzzle[j][i]].push_back(make_pair(j, i));
				h[puzzle[i][j]].push_back(make_pair(i, j));
			}
			for (int j = 1; j < 10; ++j)
			{
				if (v[j].size() > 1)
					for (int k = 0; k < v[j].size(); ++k)
						dame[v[j][k].first][v[j][k].second] = true;
				if (h[j].size() > 1)
					for (int k = 0; k < h[j].size(); ++k)
						dame[h[j][k].first][h[j][k].second] = true;
			}
		}

		for (int i = 0; i < 3; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				vector<pair<int, int> > c[10];
				for (int k = 0; k < 3; ++k)
				{
					for (int l = 0; l < 3; ++l)
					{
						int ty = i*3 + k;
						int tx = j*3 + l;
						c[puzzle[ty][tx]].push_back(make_pair(ty, tx));
					}
				}
				for (int k = 1; k < 10; ++k)
					if (c[k].size() > 1)
						for (int l = 0; l < c[k].size(); ++l)
							dame[c[k][l].first][c[k][l].second] = true;
			}
		}

		for (int i = 0; i < 9; ++i)
		{
			for (int j = 0; j < 9; ++j)
				printf("%c%d", dame[i][j] ? '*' : ' ', puzzle[i][j]);
			printf("\n");
		}
		if (n)
			printf("\n");
	}
	return 0;
}