def f(x):

    a,b=0,0

    for e in x:

        if e>a: a=e

        elif e>b: b=e

        else: return 0

    return 1



n=eval(input())

for i in range(n):

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

    print(["NO","YES"][f(D)])
def f(x):

    a,b=0,0

    for e in x:

        if e>a: a=e

        elif e>b: b=e

        else: return 0

    return 1



n=eval(input())

for i in range(n):

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

    s = ["NO","YES"][f(D)]

    print(s)
def f(x):
    a, b = 0, 0
    for e in x:
        if e > a:
            a = e
        elif e > b:
            b = e
        else:
            return 0
    return 1


n = eval(input())
for i in range(n):
    D = list(map(int, input().split()))
    print(["NO", "YES"][f(D)])

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


n = eval(input())
for i in range(n):
    D = list(map(int, input().split()))
    s = ["NO", "YES"][f(D)]
    print(s)

-    print(["NO", "YES"][f(D)]) +    s = ["NO", "YES"][f(D)] +    print(s)