n = STDIN.gets.to_i
n.times do
  tubeB = []
  tubeC = []

  balls = STDIN.gets.chop!.split(/ /)
  balls.each_with_index do |b, i|
    b = b.to_i

    topB = tubeB[tubeB.length - 1] || 0
    topC = tubeC[tubeC.length - 1] || 0

    if topB < b
      tubeB.push(b)
    elsif topC < b
      tubeC.push(b)
    else
      puts "NO"
      break
    end

    if i == balls.length - 1
      puts "YES"
    end
  end
end