def get_all_index(a, value)
  index = []
  _a = a.dup
  while _a.include?(value)
    next_i = _a.index(value)
    index << next_i
    _a[next_i] = nil
  end
  index
end

n = gets.to_i
virgin = true

n.times do
  puzzle = [] # Taro's answer
  errata = [] # errata for Taro
  
  puts "" unless virgin

  9.times do
    puzzle << gets.split.map(&:to_i)
    errata << Array.new(9, true)
  end

  # checking row and column
  0.upto(8) do |i|
    0.upto(8) do |j|
      (j+1).upto(8) do |k|
        if puzzle[i][j] == puzzle[i][k]
          errata[i][j] = false
          errata[i][k] = false
        end
        if puzzle[j][i] == puzzle[k][i]
          errata[j][i] = false
          errata[k][i] = false
        end
      end
    end
  end
  
  # checking box
  -1.upto(1) do |i|
    -1.upto(1) do |j|
      box_index << [i, j]
    end
  end
  [1,4,7].each do |i|
    [1,4,7].each do |j|
      cb = []
      cb_index = []
      box_index.each do |b|
        cb_index << [b[0] + i, b[1] + j]
        cb << puzzle[b[0] + i][b[1] + j]
      end
      if (temp = cb.uniq.select{ |x| cb.index(x) != cb.rindex(x) }).any?
        temp.each do |m|
          get_all_index(cb, m).each do |i|
            x, y = cb_index[i]
            errata[x][y] = false
          end
        end
      end
    end
  end

  # output
  0.upto(8) do |i|
    0.upto(8) do |j|
      if errata[i][j]
        print " #{puzzle[i][j]}"
      else
        print "*#{puzzle[i][j]}"
      end
      puts "" if j == 8
    end
  end

  virgin = false if virgin
end