n, h1, h2 = gets.to_i, 0, 0

n.times do
  arr, str = gets.split.map(&:to_i), "YES"
  
  arr.each do |elm|
    if h1 < elm
      h1 = elm
    elsif h2 < elm
      h2 = elm
    else
      str = "NO"
      break
    end
  end
  
  puts str
end