n=eval(input())

for i in range(n):

    dt=list(map(int, input().split()))

    a1=0

    a2=0

    for e in dt:

        if e>a1: a1=e

        elif e>a2: a2=e

        else:

            print("NO")

            break

    else:

        print("YES")
def f(x):

    a,b=0,0

    for e in x:

        if e>a: a=e

        elif e>b: b=e

        else: return False

    return True



n=eval(input())

for i in range(n):

    dt=list(map(int, input().split()))

    if f(dt): print("YES")

    else: print("NO")
n = eval(input())
for i in range(n):
    dt = list(map(int, input().split()))
    a1 = 0
    a2 = 0
    for e in dt:
        if e > a1:
            a1 = e
        elif e > a2:
            a2 = e
        else:
            print("NO")
            break
    else:
        print("YES")

def f(x):
    a, b = 0, 0
    for e in x:
        if e > a:
            a = e
        elif e > b:
            b = e
        else:
            return False
    return True


n = eval(input())
for i in range(n):
    dt = list(map(int, input().split()))
    if f(dt):
        print("YES")
    else:
        print("NO")

+def f(x): +    a, b = 0, 0 +    for e in x: +        if e > a: +            a = e +        elif e > b: +            b = e +        else: +            return False +    return True + + -    a1 = 0 -    a2 = 0 -    for e in dt: -        if e > a1: -            a1 = e -        elif e > a2: -            a2 = e -        else: -            print("NO") -            break +    if f(dt): +        print("YES") -        print("YES") +        print("NO")