#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

void init(int* c) {
	REP(i, 10) {
		c[i] = 0;
	}
}

int cy[9] = { 1, 1, 1, 4, 4, 4, 7, 7, 7 };
int cx[9] = { 1, 4, 7, 1, 4, 7, 1, 4, 7 };
int dy[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
int dx[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };

void check(int n) {

	int puz[9][9] = { 0 };
	bool err[9][9] = { 0 };

	REP(i, 9) {
		REP(j, 9) {
			cin >> puz[i][j];
		}
	}

	int* count = new int[10];
	//???????????£???
	REP(i, 9) {
		init(count);
		REP(j, 9) {
			count[puz[i][j]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(j, 9) {
					if (puz[i][j] == num) err[i][j] = true;
				}
			}
		}
	}
	//???????????£???
	REP(j, 9) {
		init(count);
		REP(i, 9) {
			count[puz[i][j]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(i, 9) {
					if (puz[i][j] == num) err[i][j] = true;
				}
			}
		}
	}
	//????????????????????£???
	REP(i, 9) {
		init(count);
		REP(j, 9) {
			count[puz[cy[i] + dy[j]][cx[i] + dx[j]]]++;
		}
		FOR(num, 1, 10) {
			if (count[num] > 1) {
				REP(j, 9) {
					if (puz[cy[i] + dy[j]][cx[i] + dx[j]] == num) err[cy[i] + dy[j]][cx[i] + dx[j]] = true;
				}
			}
		}
	}

	if (n != 0) cout << endl;
	REP(i, 9) {
		REP(j, 9) {
			cout << (err[i][j] ? '*' : ' ') << puz[i][j];
		}
		cout << endl;
	}
	
	delete[] count;
}

bool AOJ0124()
{
	int n;
	cin >> n;

	REP(i, n) {
		check(i);
	}

	return true;
}

int main()
{
	AOJ0124();

	return 0;
}