n = gets.to_i

while str = gets
  arr = str.split(' ').map(&:to_i)

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

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