n = gets.to_i
n.times{|i|
    lines = []
    9.times{lines << " " + gets.chomp}
    for y in 0..8
        temp = Array.new(10, 0)
        for x in 0..8
            temp[lines[y][x * 2 + 1].to_i] += 1
        end
        for x in 0..8
            lines[y][x * 2] = '*' if temp[lines[y][x * 2 + 1].to_i] > 1
        end
    end
    for x in 0..8
        temp = Array.new(10, 0)
        for y in 0..8
            temp[lines[y][x * 2 + 1].to_i] += 1
        end
        for y in 0..8
            lines[y][x * 2] = '*' if temp[lines[y][x * 2 + 1].to_i] > 1
        end
    end
    for a in 0..2
        for b in 0..2
            temp = Array.new(10, 0)
            for c in 0..2
                for d in 0..2
                    temp[lines[a * 3 + c][b * 6 + d * 2 + 1].to_i] += 1
                end
            end
            for c in 0..2
                for d in 0..2
                    lines[a * 3 + c][b * 6 + d * 2] = '*' if temp[lines[a * 3 + c][b * 6 + d * 2 + 1].to_i] > 1
                end
            end
        end
    end
    lines.each{|line| puts line}
    puts if i != n - 1
}
