def is_can?(a, b, remains)
  next_ball = remains.first
  return false if next_ball <= a && next_ball <= b
  return true if remains.length == 1
  if next_ball > a
    return true if is_can?(next_ball, b, remains.slice(1..(remains.length - 1)))
  else
    return is_can?(a, next_ball, remains.slice(1..(remains.length - 1)))
  end
end

count = gets.chomp.to_i
count.times do |n|
  remains = gets.chomp.split(" ").map(&:to_i)
  puts is_can?(0, 0, remains) ? "YES" : "NO"
end