#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl;
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n; cin >> n;
	rep(i, n) {
		vector<vector<pair<int, bool>>> a(9, vector<pair<int, bool>>(9));
		rep(i, 9)rep(j, 9)cin >> a[i][j].first;

		//yoko
		rep(i, 9) {
			rep(j, 8)FOR(k, j + 1, 9) {
				if (a[i][j].first == a[i][k].first) {
					a[i][j].second = true; a[i][k].second = true;
				}
			}
		}

		//tate
		rep(i, 9) {
			rep(j, 8)FOR(k, j + 1, 9) {
				if (a[j][i].first == a[k][i].first) {
					a[j][i].second = true; a[k][i].second = true;
				}
			}
		}

		//3x3
		for (int i = 0; i < 9; i += 3)for (int i2 = 0; i2 < 9; i2 += 3) {
			FOR(j, i, i + 3)FOR(j2, i2, i2 + 3) {
				FOR(k, i, i + 3)FOR(k2, i2, i2 + 3) {
					if ((j != k || j2 != k2) && a[j][j2].first == a[k][k2].first) {
						a[j][j2].second = true; a[k][k2].second = true;
					}
				}
			}
		}

		rep(i, 9) {
			rep(j, 9) {
				printf(a[i][j].second ? "*" : " ");
				cout << a[i][j].first;
			}
			puts("");
		}
		if (i != n - 1)puts("");
	}
}
