gets.to_i.times do
	number=gets.split(" ")
	
	for x in 0..number.size-1
		number[x]=number[x].to_i
	end
	
	right=[0]
	left=[0]
	
	for x in 0..number.size-1
		if number[x] > right[-1]
			right.push(number[x])
		elsif number[x] < right[-1] && number[x] > left[-1]
			left.push(number[x])
		else
			break
		end
	end
	
	if right.size + left.size == 12
		puts "YES"
	else
		puts "NO"
	end
end