Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

Python: n=input()
for _ in xrange(n):
    b=[0]
    c=[0]
    a=map(int,raw_input().split())
    for i in a:
        if b[-1]<=c[-1]:
            if c[-1]<=i:
                c.append(i)
            elif b[-1]<=i:
                b.append(i)
        else:
            if b[-1]<=i:
                b.append(i)
            elif c[-1]<=i:
                c.append(i)
    if len(b)+len(c)==len(a)+2:
        print('YES')
    else:
        print('NO')

Python: N = int(input())
for i in range(N):
    a = [int(n) for n in input().split()]
    b = []
    c = []
    jurge = "YES"
    for n in a:
        if len(b) == 0\
        or b[len(b)-1] < n:
            b.append(n)
        elif len(c) == 0\
        or c[len(c)-1] < n:
            c.append(n)
        else:
            print("NO")
            jurge = "NO"
            break
    if jurge == "YES":
        print("YES")

Python: n = int(input())
for i in range(0,n):
    a = b = 0
    arr = list(int(x) for x in input().split())
    ans = "YES"
    for j in range(0,10):
        if arr[j] < a and arr[j] < b:
            ans = "NO"
            break
        else:
            if a > b:
                if a < arr[j]:
                    a = arr[j]
                else :
                    b = arr[j]
            else:
                if b < arr[j]:
                    b = arr[j]
                else:
                    a = arr[j];
    print(ans)

Python: def main():
    n = int(input())
    for i in range(n):
        Ball = map(int,input().split())
        l = r = 0
        for value in Ball:
            if value > r:
                r = value
            elif value > l:
                l = value
            else:
                print("NO")
                r = -777
                break
            if r < l:
                r,l = l,r
            
        if r == -777:
            continue
        else:
            print("YES")

if __name__ == '__main__':
    main()

Python: def int_input():
    return list(map(int, input().split()))


def is_sorted(l):
    return all(l[i] <= l[i + 1] for i in range(len(l) - 1))


def dfs(arr, i, a, b):
    if i == 10:
        return is_sorted(a) and is_sorted(b)
    na = a + [arr[i]]
    nb = b + [arr[i]]
    return any([
        dfs(arr, i + 1, na, b) if is_sorted(na) else False,
        dfs(arr, i + 1, a, nb) if is_sorted(nb) else False])


n = int(input())
for _ in range(n):
    raw = int_input()
    print("YES" if dfs(raw, 0, list(), list()) else "NO")

Python: n = int(input())
for i in range(n):
    bs = list(map(int, input().split()))
    lanes = [0,0]
    for j in bs:
        if j > lanes[0] and  j > lanes[1]:
            lanes[lanes.index(max(lanes))] = j
        elif j>lanes[0]:
            lanes[0] = j
        elif j>lanes[1]:
            lanes[1] = j
        else:
            print('NO')
            break
    else:
        print('YES')

Python: import sys
def solve(balls):
    if distribute(balls, [], []): print('YES')
    else: print('NO')
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            if distribute(balls[1:], neoR, L): return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            if distribute(balls[1:], R, neoL): return True
    else:
        return True

def isMutch(next, lis):
    if len(lis) != 0:
        return next >= lis[len(lis)-1]
    return True

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Python: for _ in[0]*int(input()):
 b=c=f=0
 for e in map(int,input().split()):
  if e>b:b=e
  elif e>c:c=e
  else:f=1
 print(['YES','NO'][f])

Python: # AOJ 0033 Ball
# Python3 2018.6.16 bal4u

n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = c = 0
	yes = True
	for j in range(10):
		if a[j] > b: b = a[j]
		elif a[j] > c: c = a[j]
		else: yes = False
	print('YES' if yes else 'NO')

Python: for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    for i in range(10):
        if i > len(balls) - 2:
            break
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
    print('YES' if ano == sorted(ano) else 'NO')

Python: N=int(input())
answer=[]
for i in range(N):
  A=list(map(int,input().split()))
  B=[-1 for i in range(10)]
  C=[-1 for i in range(10)]
  B[0]=A[0]
  C[0]=0
  for i in range(1,10):
    if B[i-1]<A[i]:
      B[i]=A[i]
      C[i]=C[i-1]
    elif C[i-1]<A[i]:
      C[i]=A[i]
      B[i]=B[i-1]
    else:
      answer.append("NO")
      break
    if i==9:
      answer.append("YES")
for i in range(N):
  print(answer[i])

Python: N = int(input())
for n in range(N):
	str = input().split()
	list = []
	for i in str:
		list.append(int(i))
	b = []
	c = []
	ans = True

	for a in list:
		bLen = len(b)
		cLen = len(c)
		bLast = bLen - 1 if bLen > 0 else 0
		cLast = cLen - 1 if cLen > 0 else 0
		if bLen == 0 or b[bLast] < a:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLen == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
	print('YES' if ans is True else 'NO')

Python: n = int(input())
for i in range(n):
    balls = list(map(int, input().split()))
    b = c = 0
    for ball in balls:
        if b < ball:
            b = ball
        elif c < ball:
            c = ball
        else:
            print('NO')
            break
    else:
        print('YES')

Python: for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    i = 0
    while balls != sorted(balls):
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
        else:
            i += 1
    print('YES' if ano == sorted(ano) else 'NO')

Python: # -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

"""
def dfs(balls,B=-1,C=-2,cp=0):
	if cp==len(balls): 	return True
	ball = balls[cp]
	if B<ball:
		is_find = dfs(balls,ball,C,cp+1)
		if is_find: return True
	if C<ball:
		is_find = dfs(balls,B,ball,cp+1)
		if is_find: return True
	return False
"""

def dfs(balls,B=-2,C=-1,cp=0):
	if cp==len(balls): 	return True
	if C<balls[cp] and dfs(balls,B,balls[cp],cp+1): return True
	if B<balls[cp] and dfs(balls,balls[cp],B,cp+1): return True
	return False

def main():
	N = int(input().strip())
	for _ in range(N):
		balls = list(map(int,input().split(' ')))
		is_find = dfs(balls)
		if is_find:		print('YES')
		else:			print('NO')

if __name__=='__main__':
	main()

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