
def canput( list, n )
	return true if list.size == 0
	if list[ -1 ] < n
		return true
	else
		return false
	end
end

def put_try( listB, listC, left )

	return true if left.size == 0

	newleft = left.dup
	n = newleft.shift
	if canput( listB, n ) == true
		newlistB = listB.dup
		newlistC = listC.dup
		newlistB << n 
		b = put_try( newlistB, newlistC, newleft )
		return true if b
	end
	if canput( listC, n ) == true
		newlistB = listB.dup
		newlistC = listC.dup
		newlistC << n 
		b = put_try( newlistB, newlistC, newleft )
		return true if b
	end
	return false
end

def checkball( balls )
	listB = Array.new	
	listC = Array.new
	listB << balls.shift

	return put_try( listB, listC, balls )
end

answers = Array.new
num = $stdin.gets.chomp.to_i
num.times{
	list = $stdin.gets.chomp.split( /\s/ ).map{ |n| n.to_i}
	answers << checkball( list )
}
answers.each{ |a|
	if a
		puts "YES"
	else
		puts "NO"
	end
}
