N = gets.to_i

def solve(balls)
	[true, false].repeated_permutation(10){|flapper|
		b, c = [], []

		for i in 0...10 do
			flapper[i] ? b << balls[i] : c << balls[i]
		end

		return 'YES' if b == b.sort && c == c.sort
	}
	return 'NO'
end

N.times {
balls = gets.split.map &:to_i
puts solve(balls)
}

