

N = int(input())

    

for c in range(N):

    

    B = [0]

    C = [0]

    

    def dfs(depth):

        if depth == 10:

            return True

            

        res = False

        if B[-1] < A[depth]:

            B.append(A[depth])

            res |= dfs(depth+1)

            del B[-1]

        if C[-1] < A[depth]:

            C.append(A[depth])

            res |= dfs(depth+1)

            del C[-1]

        return res

    

    A = list(map(int, input().split(" ")))

    

    print("YES" if dfs(0) else "NO")

    
N = int(input())



def dfs(depth, l, r):

    if depth == 10:

        return True

    res = False

    if l < A[depth]:

        res |= dfs(depth+1, A[depth], r)

    if r < A[depth]:

        res |= dfs(depth+1, l, A[depth])

    return res



for c in range(N):

    A = list(map(int, input().split(" ")))

    print("YES" if dfs(0, 0, 0) else "NO")

    
N = int(input())
for c in range(N):
    B = [0]
    C = [0]

    def dfs(depth):
        if depth == 10:
            return True
        res = False
        if B[-1] < A[depth]:
            B.append(A[depth])
            res |= dfs(depth + 1)
            del B[-1]
        if C[-1] < A[depth]:
            C.append(A[depth])
            res |= dfs(depth + 1)
            del C[-1]
        return res

    A = list(map(int, input().split(" ")))
    print("YES" if dfs(0) else "NO")

N = int(input())


def dfs(depth, l, r):
    if depth == 10:
        return True
    res = False
    if l < A[depth]:
        res |= dfs(depth + 1, A[depth], r)
    if r < A[depth]:
        res |= dfs(depth + 1, l, A[depth])
    return res


for c in range(N):
    A = list(map(int, input().split(" ")))
    print("YES" if dfs(0, 0, 0) else "NO")

+ + +def dfs(depth, l, r): +    if depth == 10: +        return True +    res = False +    if l < A[depth]: +        res |= dfs(depth + 1, A[depth], r) +    if r < A[depth]: +        res |= dfs(depth + 1, l, A[depth]) +    return res + + -    B = [0] -    C = [0] - -    def dfs(depth): -        if depth == 10: -            return True -        res = False -        if B[-1] < A[depth]: -            B.append(A[depth]) -            res |= dfs(depth + 1) -            del B[-1] -        if C[-1] < A[depth]: -            C.append(A[depth]) -            res |= dfs(depth + 1) -            del C[-1] -        return res - -    print("YES" if dfs(0) else "NO") +    print("YES" if dfs(0, 0, 0) else "NO")