n_data = gets.to_i

n_data.times do
  last_a = 0
  last_b = 0
  is_possible = true

  nums = gets.split.map(&:to_i)
  nums.each{|n|
    if n > last_a
      last_a = n
      next
    end

    if n > last_b
      last_b = n
      next
    end

    is_possible = false
    break
  }

  puts is_possible ? "YES" : "NO"
end