n = gets.chomp.to_i
n.times do
  balls = gets.chomp.split.map(&:to_i)
  a,b = 0,0
  10.times do |i|
    if balls[i] > a || balls[i] > b
      if balls[i] < a
        b = balls[i]
      elsif balls[i] < b
        a = balls[i]
      elsif balls[i] > a && balls[i] > b
        if a > b
          a = balls[i]
        else
          b = balls[i]
        end
      end
    else
      puts "NO"
      break
    end
    print a,b
    puts ""
    puts "YES" if i == 9
  end
end