human
There is a container that is bifurcated as shown in the figure. Drop 10 balls numbered from 1 to 10 through the opening A of the container and place the balls in the left cylinder B or the right cylinder C. Since plate D can rotate left and right around the fulcrum E, you can move plate D to decide whether to put it in cylinder B or cylinder C.

Gives a sequence of balls to drop from opening A. Put them in cylinder B or cylinder C in order. At this time, create a program that outputs YES if both cylinder B and cylinder C can arrange large balls on the small numbered balls, and NO if they cannot be arranged. However, the order of the balls cannot be changed in the container. In addition, it is assumed that they can be put in the same cylinder in succession, and that there is enough room for all 10 balls in both cylinders B and C.


Input

Given multiple datasets. The number of datasets N is given in the first line. Then you are given a dataset of N rows. Each dataset is given 10 numbers, starting from the left, separated by blanks.

Output

Print YES or NO on one line for each dataset.

Example

Input

2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1

Output

YES
NO
Using python3 can you solve the prior task?
assistant
#Here is Python program to print YES or NO on one line for each dataset.

class Depth_First_Search:
    def __init__(self, bolls):
        self.bolls = bolls
        self.possible = False

    def search(self, left, right, remaining):
        if len(remaining) == 0:
            self.possible = True
        else:
            boll = remaining[0]
            if boll > max(left):
                self.search(left+[boll], right, remaining[1:])
            if boll > max(right):
                self.search(left, right+[boll], remaining[1:])

    def run(self):
        self.search([-1], [-1], self.bolls)

if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        bolls = list(map(int, input().split(' ')))
        DFS = Depth_First_Search(bolls)
        DFS.run()
        if DFS.possible:
            print('YES')
        else:
            print('NO')