Go: package main

import (
	"bufio"
		"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		table := [9][9]int{}
		check := [9][9]bool{}
		n, _ := strconv.Atoi(scanner.Text())
		for n > 0 {
			n--
			for i := 0; i < 9; i++ {
				for j := 0; j < 9; j++ {
					table[i][j] = nextInt()
				}
			}
			for i := 0; i < 9; i++ {
				for j := 0; j < 9; j++ {
					ok := true
					for k := 0; k < 9; k++ {
						if table[i][j] == table[i][k] && j != k {
							ok = false
						}
					}
					for k := 0; k < 9; k++ {
						if table[i][j] == table[k][j] && i != k {
							ok = false
						}
					}
					seci := i/3
					secj := j/3
					for k := 0; k < 3; k++ {
						for l := 0; l > 3; l++ {
							if table[seci*3+k][secj*3+l]==table[i][j]&&seci*3+k!=i&&secj*3+l!=j {
								ok = false
							}
						}
					}
					if !ok {
						check[i][j] = true
					}
				}
			}
			for i := 0; i < 9; i++ {
				for j := 0; j < 9; j++ {
					if check[i][j] {
						fmt.Print("*")
					} else {
						fmt.Print(" ")
					}
					fmt.Print(table[i][j])
				}
				fmt.Println()
			}
			if n != 0 {
				fmt.Println()
			}
		}
	}
}

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>

using namespace std;

int main(){

	int n;
	cin>>n;

	//set<pair<int,int> > wrong;

	for(int i = 0; i < n; i++){
		bool wrong[10][10];
		memset(wrong,0,sizeof(wrong));
		int field[10][10];
		for(int j = 0; j < 9; j++){
			for(int k = 0; k < 9; k++){
				cin>>field[j][k];
			}
		}
		// row
		for(int j = 0; j < 9; j++){
			vector<pair<int,int> > p[10];
			for(int k = 0; k < 9; k++){
				p[field[k][j]].push_back(make_pair(k,j));
			}
			// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
			for(int k = 1; k < 9; k++){
				if(p[k].size()>=2){
					for(int l = 0; l < p[k].size(); l++){
						//wrong.insert(p[k][l]);
						wrong[p[k][l].first][p[k][l].second]=true;
					}
				}
			}
		}
		// cow
		for(int j = 0; j < 9; j++){
			vector<pair<int,int> > p[10];
			for(int k = 0; k < 9; k++){
				p[field[j][k]].push_back(make_pair(j,k));
			}
			// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
			for(int k = 1; k < 10; k++){
				if(p[k].size()>=2){
					for(int l = 0; l < p[k].size(); l++){
						wrong[p[k][l].first][p[k][l].second]=true;
					}
				}
			}
		}
		// mergin
		for(int j = 0; j < 7; j+=3){
			for(int k = 0; k < 7; k+=3){
				if(j==9&&k==0){
					cout<<endl;
				}
				// (k,j)ツづ個地ツ点ツつゥツづァツ探ツ催オツつキツづゥ
				vector<pair<int,int> > p[10];
				for(int l = 0; l < 3; l++){
					for(int m = 0; m < 3; m++){
						p[field[j+l][k+m]].push_back(make_pair(j+l,k+m));
					}
				}
				// 2ツ禿アツ度ツ暗按湘」ツ出ツ個サツつオツづつ「ツつスツづァツ、wrongツづ永nsert
				for(int l = 1; l < 10; l++){
					if(p[l].size()>=2){
						for(int m = 0; m < p[l].size(); m++){
							wrong[p[l][m].first][p[l][m].second]=true;
						}
					}
				}
			}
		}

		for(int j = 0; j < 9; j++){
			for(int k = 0; k < 9; k++){
				if(wrong[j][k]){
					cout<<'*';
				}
				else
					cout<<' ';
				cout<<field[j][k];
			}
			cout<<endl;
		}
		cout<<endl;
	}

	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  rep(_, n) {
    vvi v(9, vi(9)), c(9, vi(9));
    rep(i, 9) rep(j, 9) cin >> v[i][j];
    rep(i, 9) rep(j, 9) {
      int x  = v[i][j];
      auto f = [&]() {
        int c = 0;
        rep(k, 9) c += v[i][k] == x;
        return c > 1;
      };
      auto g = [&]() {
        int c = 0;
        rep(k, 9) c += v[k][j] == x;
        return c > 1;
      };
      auto h = [&]() {
        int c = 0;
        rep(k, 3) rep(l, 3) c += v[i / 3 * 3 + k][j / 3 * 3 + l] == x;
        return c > 1;
      };
      c[i][j] = f() || g() || h();
    }
    rep(i, 9) {
      rep(j, 9) cout << (c[i][j] ? "*" : " ") << v[i][j];
      cout << endl;
    }
    cout << endl;
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;


int a[9][9];
bool f[9][9];


int main(){
	int n;
	cin>>n;
	while(n--){
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				cin>>a[i][j];
				f[i][j]=false;
			}
		}
		int c[10];
		for(int i=0;i<9;i++){
			memset(c,0,sizeof(c));
			for(int j=0;j<9;j++){
				c[a[i][j]]++;
			}
			for(int j=0;j<9;j++){
				if(c[a[i][j]]==2)f[i][j]=true;
			}
		}
		for(int j=0;j<9;j++){
			memset(c,0,sizeof(c));
			for(int i=0;i<9;i++){
				c[a[i][j]]++;
			}
			for(int i=0;i<9;i++){
				if(c[a[i][j]]==2)f[i][j]=true;
			}
		}
		for(int y=0;y<9;y+=3)for(int x=0;x<9;x+=3){
			memset(c,0,sizeof(c));
			for(int i=0;i<3;i++)for(int j=0;j<3;j++){
				c[a[y+i][x+j]]++;
			}
			for(int i=0;i<3;i++)for(int j=0;j<3;j++){
				if(c[a[y+i][x+j]]==2)f[y+i][x+j]=true;
			}
		}
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				if(f[i][j])cout<<'*';
				else cout<<' ';
				cout<<a[i][j];
			}
			cout<<endl;
		}
		if(n)cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	bool bf = false;
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		if (bf) cout << endl;

		int m[9][9];
		for (int y = 0; y < 9; ++y)
			for (int x = 0; x < 9; ++x) {
				cin >> m[y][x];
				--m[y][x];
			}

		bool wa[9][9] = {0};
		for (int y = 0; y < 9; ++y) {
			bool f[9] = {0}, w[9] = {0};
			for (int x = 0; x < 9; ++x)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int x = 0; x < 9; ++x)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int x = 0; x < 9; ++x) {
			bool f[9] = {0}, w[9] = {0};
			for (int y = 0; y < 9; ++y)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int y = 0; y < 9; ++y)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int y = 0; y < 3; ++y)
			for (int x = 0; x < 3; ++x) {
				bool f[9] = {0}, w[9] = {0};
				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy) {
						int nx = x * 3 + dx;
						int ny = y * 3 + dy;

						if (f[m[ny][nx]]) w[m[ny][nx]] = true;
						else f[m[ny][nx]] = true;
					}

				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy)
						if (w[m[y][x]]) wa[y][x] = true;
			}

		for (int y = 0; y < 9; ++y) {
			for (int x = 0; x < 9; ++x) {
				if (wa[y][x]) cout << "*";
				else cout << " ";

				cout << (m[y][x] + 1);
			}
			cout << endl;
		}

		bf = true;
	}
}