N = gets.to_i
N.times do
  a = gets.split(" ").map(&:to_i)
  b, c = 0, 0
  f = 0
  a.each do |n|
    if n > b
      b = n
    elsif n > c
      c = n
    else
      f = 1
    end
  end
  puts %w{YES NO}[f]
end