def s(a,i,b,c):

	return  b==sorted(b) and c==sorted(c) if i==10 else s(a,i+1,b+[a[i]],c) or s(a,i+1,b,c+[a[i]])

	

for roop in range(int(input())):

	print("YES" if s(list(map(int,input().split())),0,[],[]) else "NO")
def s(a):

	b = c = 0

	for i in a:

		if i > b:

			b = i

		elif i > c:

			c = i

		else:

			return False

	return True

	

for n in range(int(input())):

	print("YES" if s(list(map(int,input().split()))) else "NO")
def s(a, i, b, c):
    return (
        b == sorted(b) and c == sorted(c)
        if i == 10
        else s(a, i + 1, b + [a[i]], c) or s(a, i + 1, b, c + [a[i]])
    )


for roop in range(int(input())):
    print("YES" if s(list(map(int, input().split())), 0, [], []) else "NO")

def s(a):
    b = c = 0
    for i in a:
        if i > b:
            b = i
        elif i > c:
            c = i
        else:
            return False
    return True


for n in range(int(input())):
    print("YES" if s(list(map(int, input().split()))) else "NO")

-def s(a, i, b, c): -    return ( -        b == sorted(b) and c == sorted(c) -        if i == 10 -        else s(a, i + 1, b + [a[i]], c) or s(a, i + 1, b, c + [a[i]]) -    ) +def s(a): +    b = c = 0 +    for i in a: +        if i > b: +            b = i +        elif i > c: +            c = i +        else: +            return False +    return True -for roop in range(int(input())): -    print("YES" if s(list(map(int, input().split())), 0, [], []) else "NO") +for n in range(int(input())): +    print("YES" if s(list(map(int, input().split()))) else "NO")