#define _crt_secure_no_warnings

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

int main()
{
	int N;
	cin >> N;
	for (size_t p = 0; p < N; p++)
	{
		int data[9][9];
		bool ans[9][9] = {};
		for (size_t i = 0; i < 9; i++)
		{
			for (size_t j = 0; j < 9; j++)
			{
				cin >> data[i][j];
				data[i][j]--;
			}
		}
		for (size_t i = 0; i < 9; i++)
		{
			int a[9] = {}, b[9] = {};
			for (size_t j = 0; j < 9; j++)
			{
				a[data[i][j]]++;
				b[data[j][i]]++;
			}
			for (size_t j = 0; j < 9; j++)
			{
				if (a[j] != 1)
				{
					for (size_t k = 0; k < 9; k++)
					{
						if (data[i][k] == j)
						{
							ans[i][k] = 1;
						}
					}
				}
				if (b[j] != 1)
				{
					for (size_t k = 0; k < 9; k++)
					{
						if (data[k][i] == j)
						{
							ans[k][i] = 1;
						}
					}
				}
			}
		}
		for (size_t i = 0; i < 3; i++)
		{
			for (size_t j = 0; j < 3; j++)
			{
				int c[9] = {};
				for (size_t k = 0; k < 3; k++)
				{
					for (size_t l = 0; l < 3; l++)
					{
						c[data[i * 3 + k][j * 3 + l]]++;
					}
				}
				for (size_t k = 0; k < 9; k++)
				{
					if (c[k] != 1)
					{
						for (size_t l = 0; l < 3; l++)
						{
							for (size_t m = 0; m < 3; m++)
							{
								if (data[i * 3 + l][j * 3 + m] == k)
								{
									ans[i * 3 + l][j * 3 + m] = 1;
								}
							}
						}
					}
				}
			}
		}
		for (size_t i = 0; i < 9; i++)
		{
			for (size_t j = 0; j < 9; j++)
			{
				cout << (ans[i][j] ? "*" : " ") << data[i][j] + 1;
			}
			cout << endl;
		}
		if (p != N - 1)
		{
			cout << endl;
		}
	}
	return 0;
}