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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, t[10][10];

int main(){
	cin >> n;
	bool g = 0;
	REP(i, n){
		if (g)cout << endl;
		REP(i, 9)REP(j, 9)cin >> t[i][j];
		REP(i, 9){
			REP(j, 9){
				bool f = 0;
				REP(k, 9){
					if (j == k)continue;
					if (t[i][k] == t[i][j])f = 1;
				}
				REP(k, 9){
					if (i == k)continue;
					if (t[k][j] == t[i][j])f = 1;
				}
				//cout << endl;
				REP(k, 3){
					REP(l, 3){
						//cout << i / 3 * 3 + k << " " << j / 3 * 3 + l << endl;
						if (i / 3 * 3 + k == i&&j / 3 * 3 + l == j)continue;
						if (t[i / 3 * 3 + k][j / 3 * 3 + l] == t[i][j])f = 1;
					}
				}
				f ? cout << "*" : cout << " ";
				cout << t[i][j];
			}
			cout << endl;
		}
		g = 1;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool r=false;
	while(n--){
	if(r)cout<<endl;
	r=true;
	int a[9][9];
	bool d[9][9]={0};
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++){
			cin>>a[i][j];
			a[i][j]--;
		}
	}
	int t[9];
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++)t[j]=0;
		for(int j=0;j<9;j++)t[a[i][j]]++;
		for(int j=0;j<9;j++)if(t[j]>1)for(int k=0;k<9;k++)if(a[i][k]==j)d[i][k]=true;
	}
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++)t[j]=0;
		for(int j=0;j<9;j++)t[a[j][i]]++;
		for(int j=0;j<9;j++)if(t[j]>1)for(int k=0;k<9;k++)if(a[k][i]==j)d[k][i]=true;
	}
	for(int f=0;f<9;f+=3){
		for(int g=0;g<9;g+=3){
			for(int i=0;i<9;i++)t[i]=0;
			for(int i=0;i<3;i++)for(int j=0;j<3;j++)t[a[i+f][j+g]]++;
			for(int k=0;k<9;k++)if(t[k]>1){
				for(int i=0;i<3;i++)for(int j=0;j<3;j++){
					if(a[i+f][j+g]==j)d[i+f][j+g]=true;
				}
			}
		}
	}
	for(int i=0;i<9;i++){
		for(int j=0;j<9;j++){
			if(d[i][j])cout<<"*";
			else cout<<" ";
			cout<<a[i][j]+1;
		}
		cout<<endl;
	}
	}
	return 0;
}

C++: /*****include*****/
#include <iostream>
#include <set>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
/*****変数置き場*****/
	int n;
	int field[11][11];
	bool wrong[10];
	bool fail[11][11];
	int table_x[] = {0,1,2,0,1,2,0,1,2};
	int table_y[] = {0,0,0,1,1,1,2,2,2};
	set <int>appear;
	/*****処理部*****/
	cin >> n;
	while(n>0){
		n--;
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++){
				field[i][j] = 0;
				fail[i][j] = 0;
			}
		for(int i=0;i<10;i++)
			wrong[i] = false;
		for(int i=1;i<=9;i++)
			for(int j=1;j<=9;j++)
				cin >> field[i][j];
		appear.clear();
		
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				if(appear.find(field[i][j]) != appear.end()){
					wrong[field[i][j]] = true;
				}else
					appear.insert(field[i][j]);
			}
			appear.clear();
			for(int k=1;k<=9;k++)
				if(wrong[field[i][k]])
					fail[i][k] = true;
			for(int k=0;k<10;k++){
				wrong[k] = false;
			}
		}
		for(int j=1;j<=9;j++){
			for(int i=1;i<=9;i++){
				if(appear.find(field[i][j]) != appear.end()){
					wrong[field[i][j]] = true;
				}else
					appear.insert(field[i][j]);
			}
			appear.clear();
			for(int k=1;k<=9;k++)
				if(wrong[field[k][j]])
					fail[k][j] = true;
			for(int k=0;k<10;k++){
				wrong[k] = false;
			}
		}

		for(int i=1;i<=9;i+=3)
			for(int j=1;j<=9;j+=3){
				for(int k=0;k<9;k++)
					if(appear.find(field[i+table_y[k]][j+table_x[k]]) != appear.end())
						wrong[field[i+table_y[k]][j+table_x[k]]] = true;
					else
						appear.insert(field[i+table_y[k]][j+table_x[k]]);
				appear.clear();
				for(int k=0;k<9;k++)
					if(wrong[field[i+table_y[k]][j+table_x[k]]])
						fail[i+table_y[k]][j+table_x[k]] = true;
				for(int k=0;k<10;k++){
					wrong[k] = false;
				}
			}
			
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				if(fail[i][j])
					cout << "*";
				else
					cout << " ";
				cout << field[i][j];
			}
			cout << endl;
		}
		//cout << endl;
	}
	/*****処理終了後*****/
	return 0;
}

C++: #include<iostream>
#define BOARD_LEN 9
using namespace std;

void Rule_Col(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	for(int i = 0; i < BOARD_LEN; ++i){
		for(int j = 0; j < BOARD_LEN; ++j){
			int t = board[j][i];
			for(int k = 0; k < BOARD_LEN; ++k){
				if( k == j )
					continue;
				if( t == board[k][i] )
					bad[k][i] = 1;
			}
		}
	}
}
void Rule_Row(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	for(int i = 0; i < BOARD_LEN; ++i){
		for(int j = 0; j < BOARD_LEN; ++j){
			int t = board[i][j];
			for(int k = 0; k < BOARD_LEN; ++k){
				if( k == j )
					continue;
				if( t == board[i][k] )
					bad[i][k] = 1;
			}
		}
	}
}
void Rule_Square(int board[][BOARD_LEN], int bad[][BOARD_LEN]){
	const int ai[] = {1,4,7};
	const int aj[] = {1,4,7};

	for(int i = 0; i < sizeof(ai)/sizeof(*ai); ++i){
		for(int j = 0; j < sizeof(aj)/sizeof(*aj); ++j){
			const int di[] = {-1,0,1,-1,0,1,-1,0,1};
			const int dj[] = {-1,-1,-1,0,0,0,1,1,1};
			for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
				int t = board[ai[i]+di[k]][aj[j]+dj[k]];
				for(int l = 0; l < sizeof(di)/sizeof(*di); ++l){
					if( k == l )
						continue;
					if( t == board[ai[i]+di[l]][aj[j]+dj[l]] )
						bad[ai[i]+di[l]][aj[j]+dj[l]] = 1;
				}
			}
		}
	}
}
int main(void){
	int n;
	bool bFirst = true;

	cin >> n;
	for(int D = 0; D < n; ++D){
		int bad[BOARD_LEN][BOARD_LEN] ={{0,},};
		int board[BOARD_LEN][BOARD_LEN];

		if( bFirst )
			bFirst = false;
		else
			cout << '\n';

		for(int i = 0; i < sizeof(board)/sizeof(*board); ++i){
			for(int j = 0; j < sizeof(*board)/sizeof(**board); ++j){
				cin >> board[i][j];
			}
		}
		Rule_Col( board, bad );
		Rule_Row( board, bad );
		Rule_Square( board, bad );
		for(int i = 0; i < sizeof(board)/sizeof(*board); ++i){
			for(int j = 0; j < sizeof(*board)/sizeof(**board); ++j){
				if( bad[i][j] )
					cout << '*';
				else
					cout << ' ';
				cout << board[i][j];
			}
			cout << '\n';
		}
	}
	return 0;
}