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>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << endl << flush;
		}
		int hyou[9][9][2] = {0};
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				cin >> hyou[j][k][0];
			}
		}
		int hantei3[9][9] = {0};
		for (int j = 0; j < 9; j++) {
			int hantei[9] = {0};
			int hantei2[9] = {0};
			for (int k = 0; k < 9; k++) { 
				int p;
				hantei[hyou[j][k][0]-1]++; // yoko
			    hantei2[hyou[k][j][0]-1]++; // tate
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				hantei3[p][hyou[j][k][0]-1]++;
			}
			for (int k = 0; k < 9; k++) {
				if (hantei[hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
				if (hantei2[hyou[k][j][0]-1] > 1) {
					hyou[k][j][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			int p;
			for (int k = 0; k < 9; k++) { 
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				if (hantei3[p][hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				if (hyou[j][k][1] > 0) {
					cout << "*" << flush;
				} else {
					cout << " " << flush;
				}
				cout << hyou[j][k][0] << flush;
			}
			cout << endl << flush; 
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,e;
  cin>>n;
  int ku[n][9][9];
  int map[n][9][9];
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      for(int k=0;k<9;k++){
        map[i][j][k]=0;
      }
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cin>>ku[k][i][j];
      }
    }
 for(int i=0;i<9;i++){
   for(int j=0;j<9;j++){                                //tate and yoko
     for(int f=0;f<9;f++){
       if(ku[k][i][j]==ku[k][i][f]){
	 if(j!=f)map[k][i][j]=1;
       }
       if(ku[k][j][i]==ku[k][f][i]){
	 if(j!=f)map[k][j][i]=1;
       }
     }
        if(i<=2 && j<=2){       //3*3 1
	 for(int f=0;f<3;f++){
	   for(int s=0;s<3;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	       if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
	}
      else if(i<=2 && j>=3 && j<=5){       //3*3 2
	 for(int f=0;f<3;f++){ 
	   for(int s=3;s<6;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	       if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
      }
      else if(i<=2 && j>=6){       //3*3 3 
	 for(int f=0;f<3;f++){
	   for(int s=6;s<9;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	       if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
      }
      else if(i>=2 && i<=5 && j<=2){       //3*3 4
	 for(int f=3;f<6;f++){
	   for(int s=0;s<3;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	       if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
      }
      else if(i>=2 && i<=5 && j<=2 && j<=5){       //3*3 5 
	for(int f=3;f<6;f++){
	  for(int s=3;s<6;s++){
	    if(ku[k][f][s]==ku[k][i][j]){
	      if(f!=i && s!=j)map[k][i][j]=1;
	    }
	  }
	}
      }
      else if(i>=2 && i<=5 && j>=6){       //3*3 6 
	for(int f=3;f<6;f++){
	  for(int s=6;s<9;s++){
	    if(ku[k][f][s]==ku[k][i][j]){
	      if(f!=i && s!=j)map[k][i][j]=1;
	    }
	  }
	}
      }
      else if(i>=6 && j<=2){       //3*3 7 
	 for(int f=6;f<9;f++){
	   for(int s=0;s<3;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	      if(f!=i && s!=j)map[k][i][j]=1;
	     }  
	   } 
	 } 
      }
      else if(i>=6 && j>=2 && j<=5){       //3*3 8
	 for(int f=6;f<9;f++){
	   for(int s=3;s<6;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	      if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
      }
      else if(i>=6 && j>=6){       //3*3 9
	 for(int f=6;f<9;f++){
	   for(int s=6;s<9;s++){
	     if(ku[k][f][s]==ku[k][i][j]){
	       if(f!=i && s!=j)map[k][i][j]=1;
	     }
	   }
	 }
       }   
   }
 }
  }   
  for(int s=0;s<n;s++){
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	if(map[s][i][j]==0)cout<<" "<<ku[s][i][j];
	else if(map[s][i][j]==1)cout<<"*"<<ku[s][i][j];
      }  
      cout<<endl;
    }
    if(s!=n-1)cout<<endl;
  }

  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<string,int> P;

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int stage[9][9];

			int freq_x[9][10];
			int freq_y[9][10];
			int sect[9][10];

			memset(freq_x,0,sizeof(freq_x));
			memset(freq_y,0,sizeof(freq_y));
			memset(sect,0,sizeof(sect));

			for(int y=0;y<9;y++){
				for(int x=0;x<9;x++){
					scanf("%d",&stage[y][x]);
				}
			}

			for(int y=0;y<9;y++){
				for(int x=0;x<9;x++){
					freq_x[y][stage[y][x]]++;
				}
			}

			for(int x=0;x<9;x++){
				for(int y=0;y<9;y++){
					freq_y[x][stage[y][x]]++;
				}
			}

			for(int sx=0;sx<9;sx+=3){
				for(int sy=0;sy<9;sy+=3){
					for(int y=sy,i=0;i<3;y++,i++){
						for(int x=sx,j=0;j<3;x++,j++){
							sect[sy+sx/3][stage[y][x]]++;
						}
					}			
				}
			}

			for(int y=0;y<9;y++){
				for(int x=0;x<9;x++){
					printf("%s%d%s",(freq_x[y][stage[y][x]] > 1 
						|| freq_y[x][stage[y][x]] > 1
						|| sect[(y/3)*3+x/3][stage[y][x]] > 1) ? "*" : " ",stage[y][x],x == 9-1 ? "\n" : "");
				}
			}

			printf("%s",i!=n-1 ? "\n" : "");
		}
	}
}