puts gets.to_i.times.map {
  board = 9.times.map { gets.split.map(&:to_i) }
  rs = Array.new(9) { Array.new 9, false }
  (1..9).each do |x|
    9.times do |j|
      if 9.times.count {|i| board[j][i] == x } > 1
        9.times {|i| rs[j][i] = true if board[j][i] == x }
      end
    end
    9.times do |i|
      if 9.times.count {|j| board[j][i] == x } > 1
        9.times {|j| rs[j][i] = true if board[j][i] == x }
      end
    end
    3.times do |q|
      3.times do |p|
        if 3.times.reduce(0) {|r, j| r + 3.times.count {|i| board[3*q+j][3*p+i] == x } } > 1
          3.times {|j| 3.times {|i| rs[3*q+j][3*p+i] = true if board[3*q+j][3*p+i] == x } }
        end
      end
    end
  end
  9.times.map {|j| 9.times.map {|i| "#{rs[j][i] ? ?* : ' '}#{board[j][i]}" }.join + ?\n }.join
}.join ?\n