def check(seq)
	a = b = 0
	seq.each do |i|
		if a < i
			a = i
		elsif b < i
			b = i
		else
			return false
		end
	end

	return true
end

$<.gets.to_i.times do
	puts check($<.gets.split.map(&:to_i)) ? 'YES' : 'NO'
end