def foo
  i = gets.to_i
  i.times do
    max = 0
    min = 0
    list = gets.split.map(&:to_i)
    while true
      break if list.empty?
      j = list[0]
      if max < j
        max = j
      elsif min < j
        min = j
      else
        break
      end
      list.delete(j)
    end

    puts list.empty? ? 'YES' : 'NO'
  end
end
foo