N = int(eval(input()))



for testCase in range(N):

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

    ok = False

    for i in range(2 ** 10):

        x = []

        y = []

        for j in range(10):

            if i & (1 << j):

                x.append(A[j])

            else:

                y.append(A[j])

        if x == sorted(x) and y == sorted(y):

            ok = True

    if ok:

        print('YES')

    else:

        print('NO')
def dfs(i, b, c):

    if i == 11:

        return (b == sorted(b) and c == sorted(c))



    if dfs(i + 1, b + [balls[i - 1]], c):

        return True



    if dfs(i + 1, b, c + [balls[i - 1]]):

        return True



    return False





if __name__ == '__main__':

    N = int(eval(input()))

    for i in range(N):

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

        if dfs(1, [], []):

            print("YES")

        else:

            print("NO")
N = int(eval(input()))
for testCase in range(N):
    A = list(map(int, input().split()))
    ok = False
    for i in range(2**10):
        x = []
        y = []
        for j in range(10):
            if i & (1 << j):
                x.append(A[j])
            else:
                y.append(A[j])
        if x == sorted(x) and y == sorted(y):
            ok = True
    if ok:
        print("YES")
    else:
        print("NO")

def dfs(i, b, c):
    if i == 11:
        return b == sorted(b) and c == sorted(c)
    if dfs(i + 1, b + [balls[i - 1]], c):
        return True
    if dfs(i + 1, b, c + [balls[i - 1]]):
        return True
    return False


if __name__ == "__main__":
    N = int(eval(input()))
    for i in range(N):
        balls = list(map(int, input().split()))
        if dfs(1, [], []):
            print("YES")
        else:
            print("NO")

-N = int(eval(input())) -for testCase in range(N): -    A = list(map(int, input().split())) -    ok = False -    for i in range(2**10): -        x = [] -        y = [] -        for j in range(10): -            if i & (1 << j): -                x.append(A[j]) -            else: -                y.append(A[j]) -        if x == sorted(x) and y == sorted(y): -            ok = True -    if ok: -        print("YES") -    else: -        print("NO") +def dfs(i, b, c): +    if i == 11: +        return b == sorted(b) and c == sorted(c) +    if dfs(i + 1, b + [balls[i - 1]], c): +        return True +    if dfs(i + 1, b, c + [balls[i - 1]]): +        return True +    return False + + +if __name__ == "__main__": +    N = int(eval(input())) +    for i in range(N): +        balls = list(map(int, input().split())) +        if dfs(1, [], []): +            print("YES") +        else: +            print("NO")