loopNum = gets
(1..loopNum.to_i).each do |i|
	arrstr = gets
	arr =  arrstr.split
	grpA, grpB = 0, 0
	(1..10).each do |j|
		if arr[j].to_i > grpA then
			grpA = arr[j].to_i
		elsif arr[j].to_i > grpB then
			grpB = arr[j].to_i
		elsif j == 10 then
			puts "YES"
		else
			puts "NO"
			break
		end
	end
end