def foo
  i = gets.to_i
  i.times do
    left = []
    right = []
    list = gets.split.map(&:to_i)
    list.each do |j|
      if left.empty? || j > left.last
        left << j
      elsif right.empty? || j > right.last
        right << j
      end
    end

    res = list.length == (right.length + left.length) ? 'YES' : 'NO'
    puts res
  end
end

foo