require 'scanf'
require 'matrix'

n = STDIN.gets.to_i
for i in 0..n-1 do
	str = STDIN.gets
    list = \
      str.scanf("%d %d %d %d %d " \
                "%d %d %d %d %d")
    flag = true
    for i in 0..10-1 do 
        for j in i+1..10-1 do
            for k in j+1..10-1 do
                flag = false \
                    if list[i]>list[j] and list[j]>list[k]
            end
        end
    end
    print "YES\n" if flag
    print "NO\n" if not flag
end