# Original solution
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')

# Optimized solution
# 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))