import sys

from itertools import compress





def is_right_order(B, C):

    max_val = 0

    for b in B:

        if b < max_val:

            return False

        max_val = b



    max_val = 0

    for c in C:

        if c < max_val:

            return False

        max_val = c

    return True





def solve_bf(d):

    """ ??????????????§?§£??? """

    for i in range(1024):

        bin_i = '{0:010b}'.format(i)

        bin_i = [int(x) for x in bin_i]

        comp = compress(d, bin_i)

        B = list(comp)

        C = d[:]

        for b in B:

            C.remove(b)

        if is_right_order(B, C):

            return True

    return False







if __name__ == '__main__':

    # ??????????????\???

    num = int(eval(input()))

    data = []

    for _ in range(num):

        data.append(list(map(int, input().split(' '))))



    # ????????????

    for d in data:

        result = solve_bf(d)



        # ???????????¨???

        if result:

            print('YES')

        else:

            print('NO')
# import sys

from itertools import compress

# from random import shuffle, seed, random

from time import perf_counter





def is_right_order(B, C):

    """ B, C????????§??????????????????????????????(??????)????????§???????????? """

    max_val = 0

    for b in B:

        if b < max_val:

            return False

        max_val = b



    max_val = 0

    for c in C:

        if c < max_val:

            return False

        max_val = c

    return True





def solve_bf(d):

    """ ??????????????§?§£???(??????) """

    for i in range(1024):  # ????????§??????????????????????????????????????????????????????B?????????C????????????????????????

        bin_i = '{0:010b}'.format(i)

        bin_i = [int(x) for x in bin_i]

        comp = compress(d, bin_i)

        B = list(comp)

        C = d[:]

        for b in B:

            C.remove(b)

        if is_right_order(B, C):  # ???????????????????????????????????§?????¶???????????????????????????????¨???????

            return True

    return False





def solve_greed(d):

    """ ????¬????????????????

    ????????¨?????????????????????????????\????????????C?????\?????????????????\?????????B?????\?????????

    ??? ???????????????????????????????????°????????¨???????????????????????¨????????????????????????????????´?????????

    """

    used = [False] * 11  # ???????????????????????????????????????????????°?????????????????????index??????????????????used[1]?????????????????????????????§????????????+1????????????



    B = []  # ?????\????????????????????\?????????

    C = []  # ????????\???????????????????????????????????\?????????

    for b in d:

        cb = 0

        for i in range(1, 11):

            if used[i] == False:

                cb = i  # ?????????????????????????????????????????\????????????cb??¨?????¶

                break

        if b == cb:

            C.append(b)

        else:

            B.append(b)

        used[b] = True  # ????????????????????????????????????B?????????C???????????????????????????????????§????????¨?????????

    return is_right_order(B, C)





if __name__ == '__main__':

    # ??????????????\???

    num = int(eval(input()))

    data = []

    for _ in range(num):

        data.append(list(map(int, input().split(' '))))



    # ???????????¨??????????????????????????????

#    for i in range(100):

#        t = list(range(1, 11))

#        shuffle(t)

#        data.append(t)



    # start_time = perf_counter()

    # ????????????

    for d in data:

        # print('trying: {0}'.format(d))

        #result = solve_bf(d)

        result = solve_greed(d)



        if result:

            print('YES')

        else:

            print('NO')



    # end_time = perf_counter()

    # print('elapsed: {0}'.format(end_time - start_time))
import sys
from itertools import compress


def is_right_order(B, C):
    max_val = 0
    for b in B:
        if b < max_val:
            return False
        max_val = b
    max_val = 0
    for c in C:
        if c < max_val:
            return False
        max_val = c
    return True


def solve_bf(d):
    """??????????????§?§£???"""
    for i in range(1024):
        bin_i = "{0:010b}".format(i)
        bin_i = [int(x) for x in bin_i]
        comp = compress(d, bin_i)
        B = list(comp)
        C = d[:]
        for b in B:
            C.remove(b)
        if is_right_order(B, C):
            return True
    return False


if __name__ == "__main__":
    # ??????????????\???
    num = int(eval(input()))
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(" "))))
    # ????????????
    for d in data:
        result = solve_bf(d)
        # ???????????¨???
        if result:
            print("YES")
        else:
            print("NO")

# import sys
from itertools import compress

# from random import shuffle, seed, random
from time import perf_counter


def is_right_order(B, C):
    """B, C????????§??????????????????????????????(??????)????????§????????????"""
    max_val = 0
    for b in B:
        if b < max_val:
            return False
        max_val = b
    max_val = 0
    for c in C:
        if c < max_val:
            return False
        max_val = c
    return True


def solve_bf(d):
    """??????????????§?§£???(??????)"""
    for i in range(
        1024
    ):  # ????????§??????????????????????????????????????????????????????B?????????C????????????????????????
        bin_i = "{0:010b}".format(i)
        bin_i = [int(x) for x in bin_i]
        comp = compress(d, bin_i)
        B = list(comp)
        C = d[:]
        for b in B:
            C.remove(b)
        if is_right_order(
            B, C
        ):  # ???????????????????????????????????§?????¶???????????????????????????????¨???????
            return True
    return False


def solve_greed(d):
    """????¬????????????????
    ????????¨?????????????????????????????\????????????C?????\?????????????????\?????????B?????\?????????
    ??? ???????????????????????????????????°????????¨???????????????????????¨????????????????????????????????´?????????
    """
    used = [
        False
    ] * 11  # ???????????????????????????????????????????????°?????????????????????index??????????????????used[1]?????????????????????????????§????????????+1????????????
    B = []  # ?????\????????????????????\?????????
    C = []  # ????????\???????????????????????????????????\?????????
    for b in d:
        cb = 0
        for i in range(1, 11):
            if used[i] == False:
                cb = i  # ?????????????????????????????????????????\????????????cb??¨?????¶
                break
        if b == cb:
            C.append(b)
        else:
            B.append(b)
        used[
            b
        ] = True  # ????????????????????????????????????B?????????C???????????????????????????????????§????????¨?????????
    return is_right_order(B, C)


if __name__ == "__main__":
    # ??????????????\???
    num = int(eval(input()))
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(" "))))
    # ???????????¨??????????????????????????????
    #    for i in range(100):
    #        t = list(range(1, 11))
    #        shuffle(t)
    #        data.append(t)
    # start_time = perf_counter()
    # ????????????
    for d in data:
        # print('trying: {0}'.format(d))
        # result = solve_bf(d)
        result = solve_greed(d)
        if result:
            print("YES")
        else:
            print("NO")
    # end_time = perf_counter()
    # print('elapsed: {0}'.format(end_time - start_time))

-import sys +# import sys + +# from random import shuffle, seed, random +from time import perf_counter +    """B, C????????§??????????????????????????????(??????)????????§????????????""" -    """??????????????§?§£???""" -    for i in range(1024): +    """??????????????§?§£???(??????)""" +    for i in range( +        1024 +    ):  # ????????§??????????????????????????????????????????????????????B?????????C???????????????????????? -        if is_right_order(B, C): +        if is_right_order( +            B, C +        ):  # ???????????????????????????????????§?????¶???????????????????????????????¨??????? + + +def solve_greed(d): +    """????¬???????????????? +    ????????¨?????????????????????????????\????????????C?????\?????????????????\?????????B?????\????????? +    ??? ???????????????????????????????????°????????¨???????????????????????¨????????????????????????????????´????????? +    """ +    used = [ +        False +    ] * 11  # ???????????????????????????????????????????????°?????????????????????index??????????????????used[1]?????????????????????????????§????????????+1???????????? +    B = []  # ?????\????????????????????\????????? +    C = []  # ????????\???????????????????????????????????\????????? +    for b in d: +        cb = 0 +        for i in range(1, 11): +            if used[i] == False: +                cb = i  # ?????????????????????????????????????????\????????????cb??¨?????¶ +                break +        if b == cb: +            C.append(b) +        else: +            B.append(b) +        used[ +            b +        ] = True  # ????????????????????????????????????B?????????C???????????????????????????????????§????????¨????????? +    return is_right_order(B, C) +    # ???????????¨?????????????????????????????? +    #    for i in range(100): +    #        t = list(range(1, 11)) +    #        shuffle(t) +    #        data.append(t) +    # start_time = perf_counter() -        result = solve_bf(d) -        # ???????????¨??? +        # print('trying: {0}'.format(d)) +        # result = solve_bf(d) +        result = solve_greed(d) +    # end_time = perf_counter() +    # print('elapsed: {0}'.format(end_time - start_time))