N = eval(input())

for i in range(N):

    b, c = [0], [0]

    for j in map(int, input().split()):

        if b[-1] < j: b.append(j)

        elif c[-1] < j: c.append(j)

        else: break

    else:

        print('YES')

        continue

    print('NO')
N = eval(input())

for i in range(N):

    b, c = 0, 0

    for j in map(int, input().split()):

        if b < j: b = j

        elif c < j: c = j

        else: break

    else:

        print('YES')

        continue

    print('NO')
N = eval(input())
for i in range(N):
    b, c = [0], [0]
    for j in map(int, input().split()):
        if b[-1] < j:
            b.append(j)
        elif c[-1] < j:
            c.append(j)
        else:
            break
    else:
        print("YES")
        continue
    print("NO")

N = eval(input())
for i in range(N):
    b, c = 0, 0
    for j in map(int, input().split()):
        if b < j:
            b = j
        elif c < j:
            c = j
        else:
            break
    else:
        print("YES")
        continue
    print("NO")

-    b, c = [0], [0] +    b, c = 0, 0 -        if b[-1] < j: -            b.append(j) -        elif c[-1] < j: -            c.append(j) +        if b < j: +            b = j +        elif c < j: +            c = j