
require 'pp'

num = $stdin.gets.chomp.to_i
items = num.times.map {$stdin.gets.chomp.split(" ").map(&:to_i)}

def valid?(numbers, left, right)
  return [left, right] if numbers.empty?
  number = numbers.shift
  if left.empty? or left[-1] < number then
    ret = valid?(numbers.clone, left + [number], right)
    return ret if ret
  end
  if right.empty? or right[-1] < number then
    ret = valid?(numbers.clone, left, right + [number])
    return ret if ret
  end
  return false
end

items.each do |item|
  puts valid?(item, [], []) ? "YES" : "NO"
end