class Ball
  def initialize
    result = []
    n = $stdin.gets.chomp.to_i
    n.times do 
      balls = $stdin.gets.chomp.split(' ').map(&:to_i)
      flag = true
      @cup1 = [0]
      @cup2 = [0]
      balls.each do |num|
         unless insert_ball(num)
           flag = false
           break
         end
      end
      result.push((flag)?"YES":"NO")
    end

    result.each do |str|
      puts str
    end
  end

  def insert_ball(num)
    if @cup1[-1] > num && @cup2[-1] > num
      return false
    elsif @cup1[-1] > num && @cup2[-1] < num
      @cup2 << num
    elsif @cup1[-1] < num && @cup2[-1] > num
      @cup1 << num
    else 
      if @cup1[-1] > @cup2[-1]
        @cup1 << num
      else
        @cup2 << num
      end
    end
  end
end

b = Ball.new