#include <stdio.h>
int n, a[9][9], r[9][9];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		if (i) printf("\n");
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) scanf("%d", &a[j][k]), r[j][k] = 0;
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				for (int l = 0; l < 9; l++) {
					if (k != l && a[j][k] == a[j][l]) r[j][k] = 1;
					if (j != l && a[j][k] == a[l][k]) r[j][k] = 1;
				}
				for (int l = j / 3 * 3; l < j / 3 * 3 + 3; l++) {
					for (int m = k / 3 * 3; m < k / 3 * 3 + 3; m++) {
						if (j != l && k != m && a[j][k] == a[l][m]) r[j][k] = 1;
					}
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) printf("%c%d", r[j][k] ? '*' : ' ', a[j][k]);
			printf("\n");
		}
	}
}