n = gets.to_i

n.times do
    a = (1..9).map { gets.chomp.split }
    b = (0..8).map do |i|
        (0..8).map do |j|
            t = a[i][j]
            ng = a[i].count(t) > 1 ||
                 a.transpose[j].count(t) > 1 ||
                 (i/3*3..i/3*3+2).to_a.product((j/3*3..j/3*3+2).to_a).count{|k, l| a[k][l] == t} > 1
            (ng ? "*" : " ") + t
        end
    end
    puts b.map(&:join)
    puts
end