#include <cstdio>
#include <cstring>
using namespace std;

int N;
struct Pos {
	int x, y;
};

int main() {
	scanf(" %d", &N);
	for(int i = 0; i < N; i++) {
		if(i != 0) {
			puts("");
		}
		// arr[y][x]
		int arr[9][9];
		bool fail[9][9];
		memset(fail, 0, sizeof fail);

		for(int y = 0; y < 9; y++) {
			for(int x = 0; x < 9; x++) {
				scanf(" %d", &arr[y][x]);
			}
		}
		for(int x = 0; x < 9; x++) {
			int count[10];
			memset(count, 0, sizeof count);
			for(int y = 0; y < 9; y++) {
				count[arr[y][x]]++;
			}
			for(int i = 1; i <= 9; i++) {
				if(count[i] != 1) {
					for(int y = 0; y < 9; y++) {
						if(arr[y][x] == i)
							fail[y][x] = true;
					}
				}
			}
		}

		for(int y = 0; y < 9; y++) {
			int count[10];
			memset(count, 0, sizeof count);
			for(int x = 0; x < 9; x++) {
				count[arr[y][x]]++;
			}
			for(int i = 1; i <= 9; i++) {
				if(count[i] != 1) {
					for(int x = 0; x < 9; x++) {
						if(arr[y][x] == i)
							fail[y][x] = true;
					}
				}
			}
		}

		Pos p[9] = {{1, 1}, {1, 4}, {1, 7}, {4, 1}, {4, 4}, {4, 7}, {7, 1}, {7, 4}, {7, 7}};
		for(int i = 0; i < 9; i++) {
			int cx = p[i].x;
			int cy = p[i].y;
			int count[10];
			memset(count, 0, sizeof count);
			for(int x = -1; x <= 1; x++) {
				for(int y = -1; y <= 1; y++) {
					int nx = cx + x;
					int ny = cy + y;
					count[arr[ny][nx]]++;
				}
			}
			for(int j = 1; j <= 9; j++) {
				if(count[j] != 1) {
					for(int x = -1; x <= 1; x++) {
						for(int y = -1; y <= 1; y++) {
							int nx = cx + x;
							int ny = cy + y;
							if(arr[ny][nx] == j) {
								fail[ny][nx] = true;
							}
						}
					}
				}
			}
		}

		for(int y = 0; y < 9; y++) {
			for(int x = 0; x < 9; x++) {
				putchar(fail[y][x] ? '*' : ' ');
				printf("%d", arr[y][x]);
			}
			puts("");
		}
	}

	return 0;
}