#include <iostream>
#include <vector>

struct Freq {
	Freq():vector(10, 0) {};
	Freq operator+(const int &i) const {
		Freq res(*this);
		++res.vector.at(i);
		return res;
	}
	Freq &operator+=(const int &i) {
		++vector.at(i);
		return (*this);
	}
	bool operator&(const int &i) const {
		return (vector.at(i) > 1);
	}
	std::vector<char> vector;
};
static const std::vector<std::pair<int, int>> square{ std::make_pair<int, int>(0, 0), std::make_pair<int, int>(1, 0), std::make_pair<int, int>(2, 0), std::make_pair<int, int>(0, 1), std::make_pair<int, int>(1, 1), std::make_pair<int, int>(2, 1), std::make_pair<int, int>(0, 2), std::make_pair<int, int>(1, 2), std::make_pair<int, int>(2, 2) };
std::vector<std::vector<char>> check(const std::vector<std::vector<int>> &map) {
	std::vector<Freq> row(9), clum(9), sq(9);
	for (auto i = 0; i < 9; ++i) {
		int sx{ (i / 3) * 3 }, sy{ (i % 3) * 3 };
		for (auto j = 0; j < 9; ++j) {
			row.at(i) += map.at(j).at(i);
			clum.at(i) += map.at(i).at(j);
			sq.at(i) += map.at(sy + square.at(j).second).at(sx + square.at(j).first);
		}
	}
	std::vector<std::vector<char>> res(9, std::vector<char>(9, ' '));
	for (auto x = 0; x < 9; ++x) {
		for (auto y = 0; y < 9; ++y) {
			if ((row.at(x) & map.at(y).at(x)) || (clum.at(y) & map.at(y).at(x)) || (sq.at((x / 3) * 3 + (y / 3)) & map.at(y).at(x))) {
				res.at(y).at(x) = '*';
			}
		}
	}
	return res;
}
int main() {
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		if (i != 0) {
			std::cout << std::endl;
		}
		std::vector<std::vector<int>> map(9, std::vector<int>(9));
		for (auto &clum : map) {
			for (auto &cell : clum) {
				std::cin >> cell;
			}
		}
		auto res = check(map);
		for (auto y = 0; y < 9; ++y) {
			for (auto x = 0; x < 9; ++x) {
				std::cout << res.at(y).at(x) << map.at(y).at(x);
			}
			std::cout << '\n';
		}
	}
}