$a = []

def solve(n, b, c)
	return true if n == 9 and b.sort == b and c.sort == c
	return true if solve(n + 1, b << a[n], c) 
	return true if solve(n + 1, b, c << a[n])
	false
end

gets.to_i.times do 
	$a = gets.split.map(&:to_i)

	if solve(0, [], [])
		puts "YES"
	else
		puts "NO"
	end
end