n = gets.to_i

n.times do
  arr = gets.split(' ').map(&:to_i)

  left, right = [], []
  arr.each do |a|
    if (left.last || 0) < a
      left.push(a)
    elsif (right.last || 0) < a
      right.push(a)
    else
      break
    end
  end

  puts (left.size + right.size == arr.size) ? 'YES' : 'NO'
end