$debug=0
def aux(l)

  b=[0]
  c=[0]
  puts "l: #{l}" if $debug & 1==1
  while l.length > 0
    ball=l.shift
    puts "ball: #{ball} b:#{b.to_s} c:#{c.to_s}" if $debug & 1==1
    if ball > b[-1] and ball > c[-1]
      if ball-b[-1] <= ball-c[-1]
        b.push(ball)
        puts "push #{ball} to b" if $debug & 1==1
      else
        c.push(ball)
        puts "push #{ball} to c" if $debug & 1==1
      end
    elsif ball>b[-1] 
      b.push(ball)
      puts "push #{ball} to b" if $debug & 1==1
    elsif ball>c[-1] 
      c.push(ball)
      puts "push #{ball} to c" if $debug & 1==1
    else
      puts "cannot push #{ball}" if $debug & 1==1
      return "NO"
    end
  end
  return "YES"

end

def main
  dat=[]
  if $debug & 2 == 2
    fh=File.new("vol0-0033.txt", "r")
  else
    fh=STDIN
  end

  n = fh.gets.chomp.to_i
  n.times {|i|
    l=fh.gets.chomp.split.map{|x| x.to_i}
    puts aux(l)
  }

end

if $0 == __FILE__ then
  main
end
