def simulateFunc(balls)
  stk1 = 0
  stk2 = 0
  counter = 0

  balls.each do |ball|
    dif1 = ball.to_i - stk1
    dif2 = ball.to_i - stk2

    if dif1 > 0 && dif2 > 0
      if dif1 < dif2
        stk1 = ball.to_i
      else
        stk2 = ball.to_i
      end

      counter += 1
    elsif dif1 > 0
      stk1 = ball.to_i
      counter += 1
    elsif dif2 > 0
      stk2 = ball.to_i
      counter += 1
    end
  end
  
  return counter == balls.size
end

n = gets.chomp.to_i

n_test = 0
while n_test < n do
  balls = gets.chomp.split(" ");
  if simulateFunc(balls)
    puts "YES"
  else
    puts "NO"
  end
  n_test += 1
end