There is a horizontal row of $n$ cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if $cube[i]$ is on top of $cube[j]$ then $side Length[j]\geq side Length[i]$. 

When stacking the cubes, you can only pick up either the leftmost or the rightmost cube each time. Print Yes if it is possible to stack the cubes. Otherwise, print No.  

Example 

$blocks=[1,2,3,8,7]$   

Result: No  

After choosing the rightmost element, $7$, choose the leftmost element, $\mbox{I}$.  After than, the choices are $2$ and $8$.  These are both larger than the top block of size $\mbox{I}$.

$blocks=[1,2,3,7,8]$   

Result: Yes

Choose blocks from right to left in order to successfully stack the blocks.   

Input Format

The first line contains a single integer $\mathbf{T}$, the number of test cases. 

For each test case, there are $2$ lines. 

The first line of each test case contains $n$, the number of cubes. 

The second line contains $n$ space separated integers, denoting the sideLengths of each cube in that order.  

Constraints

$1\leq T\leq5$ 

$1\leq n\leq10^5$ 

$1\leq side Length<2^{31}$

Output Format

For each test case, output a single line containing either Yes or No.

Sample Input
STDIN        Function
-----        --------
2            T = 2
6            blocks[] size n = 6
4 3 2 1 3 4  blocks = [4, 3, 2, 1, 3, 4]
3            blocks[] size n = 3
1 3 2        blocks = [1, 3, 2]

Sample Output
Yes
No

Explanation

In the first test case, pick in this order: left - $\begin{array}{c}A\end{array}$, right - $\begin{array}{c}A\end{array}$, left - $3$, right - $3$, left - $2$, right - $\mbox{I}$. 

 In the second test case, no order gives an appropriate arrangement of vertical cubes. $3$ will always come after either $\mbox{I}$ or $2$.

Difficulty: MEDIUM

Starter code:

Solutions:
from collections import deque

def f(a):
	last = max(a)
	n = len(a)
	while n > 0:
		if a[0] > a[n - 1]:
			if a[0] > last:
				return 'No'
			last = a[0]
			a.popleft()
		else:
			if a[n - 1] > last:
				return 'No'
			last = a[n - 1]
			a.pop()
		n -= 1
	return 'Yes'
for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().strip().split(' ')]
	a = deque(a)
	print(f(a))


def findMin(list):
	maxPos = 0
	for i in range(len(list)):
		if list[maxPos] > list[i]:
			maxPos = i
	return maxPos

def checkIncreasing(list):
	for i in range(1, len(list)):
		if list[i - 1] > list[i]:
			return False
	return True

def checkDecreasing(list):
	for i in range(1, len(list)):
		if list[i - 1] < list[i]:
			return False
	return True

def checkList(list):
	min = findMin(list)
	A = list[:min]
	B = list[min:]
	return checkIncreasing(B) and checkDecreasing(A)
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	L = [int(i) for i in input().split()]
	ans.append(checkList(L))
for a in ans:
	if a:
		print('Yes')
	else:
		print('No')


from collections import deque
T = int(input())
for i in range(T):
	n = int(input())
	lengths = deque(map(int, input().split()))
	prev = 2147483648
	valid = 'Yes'
	while len(lengths) > 0:
		left = lengths[0]
		right = lengths[len(lengths) - 1]
		if left < right:
			if right <= prev:
				prev = lengths.pop()
			else:
				valid = 'No'
				break
		elif left <= prev:
			prev = lengths.popleft()
		else:
			valid = 'No'
			break
	print(valid)


def hit(arr, n):
	i = 0
	while arr[i] >= arr[i + 1] and i < n - 2:
		i += 1
	if i == n - 2:
		return True
	while arr[i] <= arr[i + 1] and i < n - 2:
		i += 1
	if i != n - 2:
		return False
	return arr[i] <= arr[i + 1]
t = int(input())
for i in range(0, t):
	n = int(input())
	lis = list(map(int, input().split()))
	if hit(lis, n):
		print('Yes')
	else:
		print('No')


def isValid(L):
	(l, r) = (0, len(L) - 1)
	top = max(L)
	while l <= r:
		if L[l] < L[r]:
			if top < L[r]:
				return False
			top = L[r]
			r -= 1
		else:
			if top < L[l]:
				return False
			top = L[l]
			l += 1
	return True
T = int(input())
for _ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	if isValid(l):
		print('Yes')
	else:
		print('No')


def check_ls(L):
	start = 0
	end = len(L) - 1
	c = 'Yes'
	c_max = max(L[start], L[end])
	while c == 'Yes' and start <= end:
		p_max = c_max
		c_max = max(L[start], L[end])
		if c_max > p_max:
			c = 'No'
			break
		if L[start] > L[end]:
			start += 1
		else:
			end -= 1
	print(c)
t = int(input())
for _ in range(t):
	_ = input()
	ls = list(map(int, input().split()))
	check_ls(ls)


from collections import deque

def can_arrange(cubes):
	cubes = deque(cubes)
	cube_stack = deque()
	while cubes:
		(leftmost, rightmost) = (cubes[0], cubes[-1])
		if leftmost >= rightmost:
			cube_stack.append(cubes.popleft())
		else:
			cube_stack.append(cubes.pop())
	cube_stack = tuple(cube_stack)
	for i in range(1, len(cube_stack)):
		if cube_stack[i] > cube_stack[i - 1]:
			return False
	return True
t = int(input())
for _ in range(t):
	_ = input()
	cubes = (int(cube_size) for cube_size in input().split())
	if can_arrange(cubes):
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	input()
	li = [int(x) for x in input().split()]
	i = 0
	j = len(li) - 1
	pastv = float('inf')
	while i != j:
		if li[j] >= li[i] and pastv >= li[j]:
			pastv = li[j]
			j -= 1
		elif li[i] > li[j] and pastv >= li[i]:
			pastv = li[i]
			i += 1
		else:
			print('No')
			break
	else:
		print('Yes')


T = int(input())
while T > 0:
	N = int(input())
	l = []
	l = list(map(int, input().strip().split()))
	result = max(l[0:len(l)])
	boo = True
	for i in range(0, 1):
		if i == 0 and l[i] != result and (l[N - 1] != result):
			boo = False
			break
		elif l[i] > l[len(l) - 1]:
			del l[i]
		elif l[i] == l[len(l) - 1]:
			del l[i]
		elif l[i] < l[len(l) - 1]:
			del l[len(l) - 1]
		else:
			boo = False
			break
	if not boo:
		print('No')
	else:
		print('Yes')
	T -= 1


for i in range(0, int(input())):
	n = int(input())
	string = input()
	a = [int(i) for i in string.split()]
	min_a = min(a)
	indx = a.index(min_a)
	while min_a in a:
		if indx != a.index(min_a):
			print('No')
			quit()
		a.remove(min_a)
	a1 = a[:indx]
	a2 = a[indx:]
	if a1 == sorted(a1, reverse=True) and a2 == sorted(a2):
		print('Yes')
	else:
		print('No')


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	arr = deque(map(int, input().split()))
	ans = []
	while len(arr) > 0:
		if arr[0] > arr[-1]:
			ans.append(arr[0])
			arr.popleft()
		else:
			ans.append(arr[-1])
			arr.pop()
	if all((ans[i] >= ans[i + 1] for i in range(len(ans) - 1))):
		print('Yes')
	else:
		print('No')


def check(line):
	a = line.split()
	if int(a[0]) > int(a[-1]):
		prev = int(a[0])
		del a[0]
	else:
		prev = int(a[-1])
		del a[-1]
	while a:
		if int(a[0]) > int(a[-1]) and int(a[0]) <= prev:
			prev = int(a[0])
			del a[0]
		elif int(a[-1]) <= prev:
			prev = int(a[-1])
			del a[-1]
		else:
			return False
	return True
for i in range(0, int(input())):
	if int(input() == 0):
		print('Yes')
	elif check(input().strip()):
		print('Yes')
	else:
		print('No')


from collections import deque
T = int(input())
n = 0
top = 0
sideLengths = []

def nextTop(i):
	if sideLenghts[i] > top:
		return False
	else:
		return sideLenghts.pop() if i == -1 else sideLenghts.popleft()
for t in range(T):
	n = int(input())
	sideLenghts = deque(list(map(int, input().split())))
	top = sideLenghts.popleft() if sideLenghts[0] >= sideLenghts[-1] else sideLenghts.pop()
	while len(sideLenghts) > 0:
		if sideLenghts[0] >= sideLenghts[-1]:
			top = nextTop(0)
		else:
			top = nextTop(-1)
		if top is False:
			break
	if top is False:
		print('No')
	else:
		print('Yes')


from collections import deque
cas = int(input())
for t in range(cas):
	n = int(input())
	dq = deque(list(map(int, input().split())))
	possible = True
	element = 2 ** 31 + 1
	while dq:
		left_element = dq[0]
		right_element = dq[-1]
		if left_element >= right_element and element >= left_element:
			element = dq.popleft()
		elif right_element >= left_element and element >= right_element:
			element = dq.pop()
		else:
			possible = False
			break
	if possible:
		print('Yes')
	else:
		print('No')


from collections import deque
from sys import stdin
input = stdin.readline

def solve(n):
	t = 1 << 32
	queue = deque(map(int, input().split()))
	while queue:
		if max(queue[0], queue[-1]) > t:
			return False
		if queue[0] >= queue[-1]:
			t = queue.popleft()
		else:
			t = queue.pop()
	return True
print('\n'.join((['No', 'Yes'][solve(int(input()))] for _ in range(int(input())))))


cases = int(input())
for case in range(cases):
	input()
	col = []
	row = [int(x) for x in input().split()]
	while True:
		if len(row) >= 2:
			m = max(row[0], row[-1])
			if row[0] == m:
				i = 0
			else:
				i = -1
			if len(col) == 0 or col[-1] >= m:
				col.append(m)
				del row[i]
			else:
				print('No')
				break
		elif len(row) == 1:
			if len(col) == 0 or col[-1] >= row[0]:
				col.append(row.pop())
			else:
				print('No')
				break
		else:
			print('Yes')
			break


T = int(input().rstrip())
for i in range(0, T):
	n = int(input().rstrip())
	if n == 1:
		print('Yes')
		break
	horizontal = list(map(int, input().rstrip().split(' ')))
	vertical = []
	if len(vertical) == 0:
		if horizontal[0] >= horizontal[-1]:
			vertical.append(horizontal.pop(0))
		else:
			vertical.append(horizontal.pop())
	while len(horizontal) != 0:
		if horizontal[0] >= horizontal[-1] and horizontal[0] <= vertical[-1]:
			vertical.append(horizontal.pop(0))
		elif horizontal[-1] >= horizontal[0] and horizontal[-1] <= vertical[-1]:
			vertical.append(horizontal.pop())
		else:
			break
	if len(horizontal) == 0:
		print('Yes')
	else:
		print('No')


for j in range(int(input())):
	n = int(input())
	a = [int(k) for k in input().split()]
	maxx = max(a)
	if a[0] == maxx or a[n - 1] == maxx:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	n = int(input())
	sideLengths = input().strip().split()
	sideLengths = list(map(int, sideLengths))
	if sideLengths[0] > sideLengths[n - 1]:
		bottomlevel = sideLengths[0]
	else:
		bottomlevel = sideLengths[n - 1]
	for x in range(n):
		if sideLengths[0] > sideLengths[n - x - 1]:
			nextlevel = sideLengths[0]
			del sideLengths[0]
		else:
			nextlevel = sideLengths[n - x - 1]
			sideLengths.pop()
		if bottomlevel >= nextlevel:
			bottomlevel = nextlevel
		else:
			print('No')
			break
		if len(sideLengths) == 0:
			print('Yes')
			break


from collections import deque
for i in range(int(input())):
	input()
	d = deque((int(x) for x in input().split()))
	if d[0] < d[-1]:
		tmp = d.pop()
	else:
		tmp = d.popleft()
	while len(d) > 0:
		if tmp >= d[-1] and d[0] <= d[-1]:
			tmp = d.pop()
		elif tmp >= d[0]:
			tmp = d.popleft()
		else:
			print('No')
			d.clear()
			break
		if not len(d):
			print('Yes')


T = int(input())
for t in range(T):
	_unused = input()
	row = list(map(int, input().split()))
	left = 0
	right = len(row) - 1
	cube = max(row[left], row[right])
	possible = True
	while left < right:
		if row[left] > row[right]:
			if row[left] > cube:
				possible = False
				break
			cube = row[left]
			left += 1
		else:
			if row[right] > cube:
				possible = False
				break
			cube = row[right]
			right -= 1
	if possible:
		print('Yes')
	else:
		print('No')


from collections import deque
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	d = deque(arr)
	prev = 10000000000
	while len(d) > 0:
		k = len(d)
		if d[len(d) - 1] > d[0]:
			if d[len(d) - 1] <= prev:
				prev = d[len(d) - 1]
				d.pop()
			else:
				break
		elif d[0] <= prev:
			prev = d[0]
			d.popleft()
		else:
			break
	if len(d) == 0:
		print('Yes')
	else:
		print('No')


lengths = []
for _ in range(int(input())):
	n = int(input())
	lengths = [int(x) for x in input().split()]
	current_length = float('inf')
	left = 0
	right = len(lengths) - 1
	while left <= right:
		if max(current_length, lengths[left], lengths[right]) != current_length:
			print('No')
			break
		elif lengths[left] >= lengths[right]:
			current_length = lengths[left]
			left += 1
		else:
			current_length = lengths[right]
			right -= 1
	else:
		print('Yes')


from collections import deque
n = int(input())
testcase = dict()
test = []
for i in range(n):
	x = input()
	test.append(list(map(int, input().split())))

def piling(test):
	for case in test:
		d = deque(case)
		if d[0] >= d[-1]:
			top = d[0]
			d.popleft()
		else:
			top = d[-1]
			d.pop()
		a = 0
		while a == 0:
			if len(d) == 0:
				break
			if top >= d[0] and d[0] >= d[-1]:
				top = d[0]
				d.popleft()
			elif top >= d[-1] and d[-1] > d[0]:
				top = d[-1]
				d.pop()
			else:
				print('No')
				a = 1
		if a == 0:
			print('Yes')
piling(test)


import sys

def test_cubes(cubes):
	t_cube = 0
	if cubes[0] > cubes[len(cubes) - 1]:
		t_cube = cubes[0]
		cubes.pop(0)
	else:
		t_cube = cubes[len(cubes) - 1]
		cubes.pop(len(cubes) - 1)
	while len(cubes) > 0:
		if t_cube == cubes[0]:
			t_cube = cubes.pop(0)
		elif t_cube == cubes[len(cubes) - 1]:
			t_cube = cubes.pop(len(cubes) - 1)
		elif cubes[0] > cubes[len(cubes) - 1] and t_cube >= cubes[0]:
			t_cube = cubes.pop(0)
		elif cubes[0] < cubes[len(cubes) - 1] and t_cube >= cubes[len(cubes) - 1]:
			t_cube = cubes.pop(len(cubes) - 1)
		elif cubes[0] == cubes[len(cubes) - 1]:
			t_cube = cubes.pop(0)
		else:
			return 'No'
	return 'Yes'
num_of_tests = sys.stdin.readline().strip()
num_of_tests = int(num_of_tests)
for i in range(0, num_of_tests):
	sys.stdin.readline()
	cubes = list(map(int, sys.stdin.readline().strip().split(' ')))
	print(test_cubes(cubes))


testcases_count = int(input())
for i in range(testcases_count):
	count = int(input())
	numbers = list(map(int, input().split()))
	sortedNum = list(numbers)
	sortedNum.sort()
	sortedNum.reverse()
	while len(numbers) > 0:
		if numbers[0] == sortedNum[0]:
			numbers.pop(0)
			sortedNum.pop(0)
		elif numbers[-1] == sortedNum[0]:
			numbers.pop(-1)
			sortedNum.pop(0)
		else:
			break
	if len(numbers) > 0:
		print('No')
	else:
		print('Yes')


n = int(input())
for _ in range(n):
	_ = input()
	line = list(map(int, input().strip().split()))
	increasing = False
	ret_str = 'Yes'
	for i in range(len(line) - 1):
		if not increasing and line[i] < line[i + 1]:
			increasing = True
		elif increasing and line[i] > line[i + 1]:
			ret_str = 'No'
			break
	print(ret_str)


def test(lis, n):
	m = 2 ** 31
	a = 0
	b = n - 1
	while a <= b:
		if lis[a] > lis[b]:
			if lis[a] > m:
				return False
			m = lis[a]
			a += 1
		else:
			if lis[b] > m:
				return False
			m = lis[b]
			b -= 1
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	if test(lis, n):
		print('Yes')
	else:
		print('No')


from itertools import zip_longest

def possible(x, cubes):
	cubes2 = cubes[:]
	cubes2.sort(reverse=True)
	start = 0
	end = -1
	for i in cubes2:
		if cubes[start] == i:
			start += 1
		elif cubes[end] == i:
			end -= 1
		else:
			return False
	return True
from collections import deque
n = int(input())
test = []
for i in range(n):
	x = int(input())
	cubes = list(map(int, input().split()))
	print(('No', 'Yes')[possible(x, cubes)])


from collections import deque

def __starting_point():
	t = int(input().strip())
	for _ in range(t):
		num_cnt = int(input().strip())
		deq = deque(list(map(int, input().strip().split(' '))))
		prev = max(deq[0], deq[-1])
		while deq:
			if prev >= deq[0] and prev >= deq[-1]:
				if deq[0] >= deq[-1]:
					prev = deq.popleft()
				else:
					prev = deq.pop()
			else:
				break
		if len(deq) == 0:
			print('Yes')
		else:
			print('No')
__starting_point()


N = int(input())
for n in range(0, N):
	T = int(input())
	cubes = list((int(x) for x in input().replace('\r', '').strip().split(' ')))
	i = 0
	j = len(cubes) - 1
	cur = max(cubes[i], cubes[j])
	erg = 'Yes'
	while j - i > -1:
		if cubes[i] > cubes[j]:
			nex = cubes[i]
			i += 1
		else:
			nex = cubes[j]
			j -= 1
		if nex > cur:
			erg = 'No'
			break
		cur = nex
	print(erg)


t = int(input())
while t > 0:
	n = int(input())
	lis = input().split()
	lis = list(map(int, lis))
	i = 0
	j = len(lis) - 1
	if lis[i] > lis[j]:
		prev = lis[i]
		i = i + 1
	else:
		prev = lis[j]
		j = j - 1
	while i < j:
		if lis[i] > lis[j]:
			p = lis[i]
			if p > prev:
				break
			i = i + 1
		else:
			p = lis[j]
			if p > prev:
				break
			j = j - 1
		prev = p
	if i < j:
		print('No')
	else:
		print('Yes')
	t = t - 1


from collections import deque
N = int(input())
for i in range(N):
	answer = ''
	cases = deque()
	input()
	string = input().strip().split()
	for element in string:
		cases.append(int(element))
	last = float('inf')
	while len(cases) > 1:
		front = int(cases.pop())
		rear = int(cases.popleft())
		if front >= rear and front <= last:
			cases.appendleft(rear)
			last = front
		elif rear <= last:
			cases.append(front)
			last = rear
		else:
			answer = 'No'
			break
	if len(cases) == 1 and cases.pop() <= last and (answer != 'No'):
		answer = 'Yes'
	else:
		answer = 'No'
	print(answer)


from collections import deque
t = int(input())
for _ in range(t):
	N = int(input())
	arr = deque([int(x) for x in input().split()])
	curr = arr.popleft() if arr[0] > arr[N - 1] else arr.pop()
	while len(arr) > 0:
		curr_new = arr.popleft() if arr[0] > arr[len(arr) - 1] else arr.pop()
		if curr < curr_new:
			break
	print('No' if len(arr) > 0 else 'Yes')


from collections import deque
t = int(input())
for i in range(t):
	n = int(input())
	d = deque(map(int, input().split()))
	last = max(d[-1], d[0])
	while len(d) > 0:
		if d[-1] > d[0]:
			e = d.pop()
		else:
			e = d.popleft()
		if e <= last:
			last = e
		else:
			break
	if len(d) > 0:
		print('No')
	else:
		print('Yes')


def pile():
	n = int(input())
	cubes = list(map(int, input().split()))
	pile = [float('infinity')]
	while len(cubes) > 0:
		if cubes[0] >= cubes[-1]:
			if cubes[0] <= pile[-1]:
				pile.append(cubes.pop(0))
			else:
				return 'No'
		elif cubes[-1] <= pile[-1]:
			pile.append(cubes.pop())
		else:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	print(pile())


num = int(input())
for i in range(num):
	seqNum = int(input())
	seq = input()
	seq = list(map(int, seq.split()))
	head = 0
	tail = len(seq) - 1
	Max = max(seq[head], seq[tail])
	while head <= tail:
		if seq[head] >= seq[tail]:
			tmpMax = seq[head]
			head += 1
		else:
			tmpMax = seq[tail]
			tail -= 1
		if tmpMax <= Max:
			Max = tmpMax
		else:
			print('No')
			break
	if head == tail + 1:
		print('Yes')


import sys
cases = int(next(sys.stdin).strip())
for c in range(cases):
	s = int(next(sys.stdin).strip())
	cubes = [int(x) for x in next(sys.stdin).strip().split()]
	max_c = 2 ** 31
	for i in range(s):
		(l, r) = (cubes[0], cubes[-1])
		if l > max_c or r > max_c:
			print('No')
			break
		if l > r:
			max_c = cubes.pop(0)
		else:
			max_c = cubes.pop()
	else:
		print('Yes')


for _ in range(int(input())):
	(p, pile) = (int(input()), list(map(int, input().strip().split())))
	diff = [pile[i] - pile[i + 1] for i in range(p - 1)]
	i = 0
	while i < p - 1 and diff[i] >= 0:
		i += 1
	while i < p - 1 and diff[i] <= 0:
		i += 1
	if i == p - 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for _ in range(T):
	leng = int(input())
	L = list(map(int, input().split()))
	start = 0
	end = leng - 1
	Top = 99999999999
	status = 'Yes'
	while True:
		if L[start] >= L[end]:
			ele = L[start]
			start = start + 1
		else:
			ele = L[end]
			end = end - 1
		if ele > Top:
			status = 'No'
			break
		Top = ele
		if start > end:
			break
	print(status)


from collections import deque
N = int(input())
for i in range(N):
	n = int(input())
	sideLengths = deque(map(int, input().strip().split()))
	top = max(sideLengths[0], sideLengths[-1])
	result = 0
	while result == 0:
		if len(sideLengths) == 0:
			break
		elif top >= max(sideLengths[0], sideLengths[-1]):
			if sideLengths[0] >= sideLengths[-1]:
				top = sideLengths[0]
				sideLengths.popleft()
			elif sideLengths[-1] > sideLengths[0]:
				sideLengths.pop()
		else:
			result = 1
			print('No')
	if result == 0:
		print('Yes')


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	l = map(int, input().split())
	q = deque(l)
	m = max(q[0], q[-1])
	for _ in range(n):
		if max(q[0], q[-1]) <= m:
			if q[0] >= q[-1]:
				m = q[0]
				q.popleft()
			else:
				m = q[-1]
				q.pop()
		else:
			break
	if not q:
		print('Yes')
	else:
		print('No')


from collections import deque

def vertical_pile(n, cubes):
	pile = [max(cubes)]
	while n > 0:
		if cubes[0] >= cubes[-1] and cubes[0] <= pile[-1]:
			pile.append(cubes.popleft())
			n -= 1
		elif cubes[-1] > cubes[0] and cubes[-1] <= pile[-1]:
			pile.append(cubes.pop())
			n -= 1
		else:
			return 'No'
	return 'Yes'
test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	cubes = input().split(' ')
	if cubes[-1] == '':
		del cubes[-1]
	cubes = deque(map(int, cubes))
	print(vertical_pile(n, cubes))


N = int(input())
if N == 0:
	print('No')
for i in range(0, N):
	cubnum = int(input())
	cublist = input().split()
	control1 = True
	min1 = 0
	min2 = 0
	for x in range(0, cubnum - 1):
		if int(cublist[x + 1]) > int(cublist[x]):
			min1 = x
			break
	for x in range(cubnum - 1, -1, -1):
		if int(cublist[x]) < int(cublist[x - 1]):
			min2 = x
			break
	if min1 >= min2:
		print('Yes')
	else:
		print('No')


from collections import deque
T = int(input())
for _ in range(T):
	n = int(input())
	ls = deque(map(int, input().strip().split()))
	top_length = 99999999999999999999
	for _ in range(n):
		if ls[0] >= ls[-1] and ls[0] <= top_length:
			top_length = ls.popleft()
		elif ls[0] < ls[-1] and ls[-1] <= top_length:
			top_length = ls.pop()
		else:
			break
	if len(ls) > 0:
		print('No')
	else:
		print('Yes')


def run():
	input()
	arr = [int(x) for x in input().split()]
	top = 2 ** 31
	left = 0
	right = len(arr) - 1
	while left < right:
		if arr[left] >= arr[right] and arr[left] <= top:
			top = arr[left]
			left += 1
		elif arr[right] <= top:
			top = arr[right]
			right -= 1
		else:
			return 'No'
	return 'Yes'
for _ in range(int(input())):
	print(run())


tc = int(input())
for i in range(tc):
	n = int(input())
	cube = list(map(int, input().split()))
	base = pow(2, 31) + 1
	for j in range(n):
		end = len(cube) - 1
		if base < cube[0] or base < cube[end]:
			print('No')
			break
		elif cube[0] > cube[end]:
			base = cube[0]
			cube.pop(0)
		else:
			base = cube[end]
			cube.pop(end)
	if j == n - 1:
		print('Yes')


import math

def ord_list(l):
	l_return = []
	for i in range(len(l)):
		x = l[0]
		y = l[-1]
		if x >= y:
			l_return.append(x)
			l.pop(0)
		else:
			l_return.append(y)
			l.pop()
	if len(l) % 2 == 1:
		l_return = l_return[0:-1]
	return l_return

def is_ord(l):
	ordo = True
	for i in range(1, len(l)):
		if not l[i - 1] >= l[i]:
			ordo = False
	return ordo
n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().strip().split()))
	ord_l = ord_list(l)
	if is_ord(ord_l):
		print('Yes')
	else:
		print('No')


import collections
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = collections.deque(l)
	is_it_possible = True
	previous_val = 0
	while True:
		try:
			first = d[0]
			last = d[-1]
			if previous_val != 0 and (first > previous_val or last > previous_val):
				is_it_possible = False
				break
			if first >= last:
				previous_val = d.popleft()
			else:
				previous_val = d.pop()
		except IndexError:
			break
	if is_it_possible:
		print('Yes')
	else:
		print('No')


def isPossible(cubes):
	count = len(cubes)
	past = False
	for c in range(count):
		first = cubes[0]
		last = cubes[-1]
		if first >= last:
			cube = cubes.pop(0)
		else:
			cube = cubes.pop()
		if past == False:
			past = cube
		elif past >= cube:
			past = cube
		else:
			return False
	return True
test_cases = int(input())
for c in range(test_cases):
	cube_count = int(input())
	cubes = [int(x) for x in input().split()]
	possible = isPossible(cubes)
	print('Yes' if possible else 'No')


def outerMax(xs):
	return (xs[0], 0) if xs[0] >= xs[-1] else (xs[-1], -1)

def pile(xs):
	bottom = outerMax(xs)
	while xs:
		if bottom < outerMax(xs):
			return False
		bottom = outerMax(xs)
		del xs[bottom[1]]
	return True
for _ in range(int(input())):
	input()
	xs = list(map(int, input().split()))
	print('Yes') if pile(xs) else print('No')


from collections import deque
num_test_cases = int(input())
test_cases = []
for _ in range(num_test_cases):
	(line1, line2) = [input() for _ in range(2)]
	n = int(line1)
	side_lengths = map(int, line2.split())
	test_cases.append(side_lengths)

def test_cubes(cubes):
	cube_stack = deque(cubes)
	max_cube = 0
	while cube_stack:
		if len(cube_stack) == 1:
			cube = cube_stack.pop()
		else:
			left_is_greater = cube_stack[0] >= cube_stack[-1]
			cube = cube_stack.popleft() if left_is_greater else cube_stack.pop()
		if max_cube != 0 and cube > max_cube:
			return 'No'
		max_cube = cube
	return 'Yes'
for cubes in test_cases:
	print(test_cubes(cubes))


from collections import deque

def test(A):
	if len(A) < 3:
		return 1
	L = 0
	R = 0
	sq = float('inf')
	while len(A) > 0:
		if L == 0:
			try:
				L = A.popleft()
			except:
				break
		if R == 0:
			try:
				R = A.pop()
			except:
				break
		if max(L, R) > sq:
			return 0
		if L > R:
			sq = L
			L = 0
		else:
			sq = R
			R = 0
	m = max(L, R)
	if m <= sq:
		return 1
	return 0
for tests in range(int(input())):
	n = int(input())
	A = deque((int(i) for i in input().split()))
	if test(A):
		print('Yes')
	else:
		print('No')


__author__ = 'kr15hn4'
t = int(input())
while t > 0:
	n = int(input())
	li = []
	li = list(map(int, input().strip().split()))
	res = max(li[0:len(li)])
	gg = True
	for i in range(0, 1):
		if i == 0 and li[i] != res and (li[n - 1] != res):
			gg = False
			break
		elif li[i] > li[len(li) - 1]:
			del li[i]
		elif li[i] == li[len(li) - 1]:
			del li[i]
		elif li[i] < li[len(li) - 1]:
			del li[len(li) - 1]
		else:
			gg = False
			break
	if not gg:
		print('No')
	else:
		print('Yes')
	t -= 1


from collections import deque
T = int(input())
for ti in range(T):
	canstack = True
	n = int(input())
	l = [int(__) for __ in input().split()]
	d = deque(l)
	left = d.popleft()
	right = d.pop()
	if left > right:
		top = left
		usedLeft = True
	else:
		top = right
		usedLeft = False
	for ni in range(n - 2):
		if usedLeft:
			left = d.popleft()
		else:
			right = d.pop()
		if left > right:
			if left <= top:
				top = left
				usedLeft = True
			else:
				canstack = False
				break
		elif right <= top:
			top = right
			usedLeft = False
		else:
			canstack = False
			break
	if canstack:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	input()
	m = [int(v) for v in input().split()]
	direction = 1
	for (i, v) in enumerate(m):
		if i == len(m) - 1:
			continue
		if direction == 1:
			if v < m[i + 1]:
				direction = -1
				continue
		elif direction == -1:
			if v > m[i + 1]:
				print('No')
				break
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a_min = min(a)
	indx = a.index(a_min)
	while a_min in a:
		if indx != a.index(a_min):
			print('No')
			quit()
		a.remove(a_min)
	a1 = a[:indx]
	a2 = a[indx:]
	if a1 == sorted(a1, reverse=True) and a2 == sorted(a2):
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	input()
	cube_lengths = [int(n) for n in input().strip().split(' ')]
	current_cube_length = max(cube_lengths[0], cube_lengths[-1])
	while cube_lengths:
		if cube_lengths[0] >= cube_lengths[-1] and cube_lengths[0] <= current_cube_length:
			current_cube_length = cube_lengths.pop(0)
		elif cube_lengths[-1] <= current_cube_length:
			current_cube_length = cube_lengths.pop()
		else:
			print('No')
			break
	else:
		print('Yes')


testcases = int(input())
while testcases != 0:
	testcases -= 1
	numberofDices = int(input())
	listDices = [int(element) for element in input().split()]
	lb = 0
	ub = len(listDices) - 1
	previous = 2147483649
	flag = 1
	while lb <= ub:
		if listDices[lb] >= listDices[ub]:
			if listDices[lb] > previous:
				flag = 0
				break
			else:
				previous = listDices[lb]
				lb += 1
		elif listDices[ub] > previous:
			flag = 0
			break
		else:
			previous = listDices[ub]
			ub -= 1
	if flag == 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	n = int(input())
	cubes = list(map(int, str(input()).split()))
	prevCube = float('inf')
	stackable = False
	for j in range(n):
		if prevCube >= max(cubes[0], cubes[len(cubes) - 1]) and cubes[0] > cubes[len(cubes) - 1]:
			prevCube = cubes.pop(0)
		elif prevCube >= max(cubes[0], cubes[len(cubes) - 1]) and cubes[0] < cubes[len(cubes) - 1]:
			prevCube = cubes.pop(len(cubes) - 1)
		elif prevCube >= max(cubes[0], cubes[len(cubes) - 1]) and cubes[0] == cubes[len(cubes) - 1]:
			prevCube = cubes.pop(0)
		else:
			break
		if len(cubes) == 0:
			stackable = True
	if stackable:
		print('Yes')
	else:
		print('No')


__author__ = 'Maciej'
Z = int(input())
while Z > 0:
	n = int(input())
	cubelist = input().split(' ')
	cubelist = [int(x) for x in cubelist if x != '']
	controlflag = True
	i = 1
	while i < cubelist.__len__() and cubelist[i - 1] >= cubelist[i]:
		i += 1
	while i < cubelist.__len__() and cubelist[i - 1] <= cubelist[i]:
		i += 1
	if i == cubelist.__len__():
		print('Yes')
	else:
		print('No')
	Z -= 1


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	max = pow(2, 31)
	for j in range(m):
		if l[0] > l[-1]:
			if l[0] <= max:
				max = l[0]
				l.pop(0)
			else:
				print('No')
				break
		elif l[-1] <= max:
			max = l[-1]
			l.pop()
		else:
			print('No')
			break
	else:
		print('Yes')


from collections import deque
num_cases = int(input())
for _ in range(num_cases):
	case_length = int(input())
	vals = deque(map(int, input().split()))
	j = max(vals) + 1
	while vals:
		if vals[0] > j or vals[-1] > j:
			print('No')
			break
		if vals[0] > vals[-1]:
			j = vals.popleft()
		else:
			j = vals.pop()
	else:
		print('Yes')


from collections import deque

def solve(arr):
	if len(arr) < 3:
		return 'Yes'
	dqe = deque(arr)
	(left, right) = (dqe.popleft(), dqe.pop())
	last = max(left, right)
	des = True
	while True:
		if left >= right:
			if last >= left:
				last = left
				des = True
			else:
				return 'No'
		elif last >= right:
			last = right
			des = False
		else:
			return 'No'
		if len(dqe) > 0:
			if des:
				left = dqe.popleft()
			else:
				right = dqe.pop()
		else:
			return 'Yes'
num_cases = int(input())
for _ in range(num_cases):
	input()
	print(solve([int(i) for i in input().split()]))


T = int(input())
for t in range(T):
	n = int(input())
	size = list(map(int, input().split()))
	inc = False
	can = True
	for i in range(1, n):
		if not inc and size[i - 1] < size[i]:
			inc = True
		if inc and size[i - 1] > size[i]:
			can = False
			break
	print('Yes' if can else 'No')


import sys

def solve():
	n = int(input().strip())
	sd = list(map(int, input().strip().split(' ')))
	i = 0
	j = len(sd) - 1
	last = sys.maxsize
	while j > i:
		if max(sd[i], sd[j]) > last:
			return False
		if sd[i] > sd[j]:
			last = sd[i]
			i = i + 1
		else:
			last = sd[j]
			j = j - 1
	return True
t = int(input().strip())
while t > 0:
	if solve():
		print('Yes')
	else:
		print('No')
	t = t - 1


t = int(input())

def test_case(cubes):
	result_list = []
	while cubes:
		if cubes[0] > cubes[-1]:
			result_list.append(cubes.pop(0))
		else:
			result_list.append(cubes.pop(-1))
		if len(result_list) > 1 and result_list[-2] < result_list[-1]:
			return False
	return True
for _ in range(t):
	n = int(input())
	cubes = list(map(int, input().split()))
	if test_case(cubes):
		print('Yes')
	else:
		print('No')


def is_pileable(n, lens):
	(l, r) = (0, n - 1)
	base = max(lens[l], lens[r])
	while l < r:
		m = max(lens[l], lens[r])
		if m > base:
			return 'No'
		elif m == lens[l]:
			l += 1
		else:
			r -= 1
	return 'Yes'
t = int(input())
for i in range(t):
	n = int(input())
	lens = [int(s) for s in input().split()]
	print(is_pileable(n, lens))


from collections import deque
t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	stack = deque(lis)
	q = max(stack[0], stack[-1])
	find = 'Yes'
	while find == 'Yes':
		if len(stack) == 0:
			break
		else:
			m = max(stack[0], stack[-1])
			if m <= q:
				l = stack[0]
				r = stack[-1]
				if l == m:
					stack.popleft()
				else:
					stack.pop()
				q = m
			else:
				find = 'No'
	print(find)


t = int(input().strip())
for _ in range(t):
	n = int(input())
	mylist = [int(x) for x in input().strip().split(' ')]
	if len(mylist) < 3:
		print('Yes')
		continue
	prev = mylist[1]
	initialdecreasing = True if mylist[0] - prev >= 0 else False
	decreasing = initialdecreasing
	change = 0
	for x in range(2, n):
		decopy = decreasing
		if prev - mylist[x] > 0:
			decreasing = True
		elif prev - mylist[x] > 0:
			decreasing = False
		else:
			pass
		if decopy != decreasing:
			change += 1
	if change == 0 or (change == 1 and initialdecreasing == True):
		print('Yes')
	else:
		print('No')


def Possible(sideLengths, n):
	i = 0
	j = n - 1
	pickedBlock = float('inf')
	while i <= j:
		if sideLengths[i] > sideLengths[j]:
			if sideLengths[i] <= pickedBlock:
				pickedBlock = sideLengths[i]
				i += 1
			else:
				return 'No'
		elif sideLengths[j] <= pickedBlock:
			pickedBlock = sideLengths[j]
			j -= 1
		else:
			return 'No'
	return 'Yes'
T = int(input())
for _ in range(0, T):
	n = int(input())
	sideLengths = list(map(int, input().split()))
	print(Possible(sideLengths, n))


from collections import deque
r = lambda : list(map(int, input().strip().split(' ')))
p = lambda d: d.popleft() if d[0] >= d[-1] else d.pop()
for T in range(r()[0]):
	r()
	d = deque(r())
	stack = [p(d)]
	while len(d) > 0:
		stack.append(p(d))
	valid = 'Yes'
	for i in range(1, len(stack)):
		if stack[i] > stack[i - 1]:
			valid = 'No'
			break
	print(valid)


from collections import deque

def foo(lengths):
	s = []
	while len(lengths) > 0:
		l = lengths[0]
		r = lengths[-1]
		if l > r:
			s.append(lengths.popleft())
		else:
			s.append(lengths.pop())
	if len(s) == 0:
		return 'Yes'
	t = s.pop()
	while len(s) > 0:
		i = s.pop()
		if i < t:
			return 'No'
		t = i
	return 'Yes'
for T in range(int(input())):
	n = int(input())
	print(foo(deque(map(int, input().split()))))


from collections import deque
n_o_test_cases = int(input())
for i in range(n_o_test_cases):
	no = False
	size = int(input())
	queue = deque(map(int, input().split()))
	left_number = queue[0]
	right_number = queue[-1]
	if left_number >= right_number:
		current_number = queue.popleft()
	else:
		current_number = queue.pop()
	last_number = current_number
	for i in range(size - 1):
		last_number = current_number
		left_number = queue[0]
		right_number = queue[-1]
		if left_number >= right_number:
			current_number = queue.popleft()
		else:
			current_number = queue.pop()
		if current_number > last_number:
			no = True
			print('No')
			break
	if not no:
		print('Yes')


import collections

def is_vertical_pile_possible(row):
	deque = collections.deque(row)
	previous = float('inf')
	while deque:
		left = deque[0]
		right = deque[-1]
		if left >= right:
			popped = deque.popleft()
		else:
			popped = deque.pop()
		if popped > previous:
			return False
		previous = popped
	return True
t = int(input())
for _ in range(t):
	input()
	print('Yes' if is_vertical_pile_possible(map(int, input().split())) else 'No')


T = int(input().strip())
for itr in range(T):
	n = int(input().strip())
	blocks = list(map(int, input().strip().split(' ')))
	base_blk = 2 ** 31
	res = 'Yes'
	for itr in range(len(blocks)):
		end = len(blocks) - 1
		if end == -1:
			break
		if blocks[0] >= blocks[end] and blocks[0] <= base_blk:
			base_blk = blocks[0]
			blocks.pop(0)
		elif blocks[end] >= blocks[0] and blocks[end] <= base_blk:
			base_blk = blocks[end]
			blocks.pop(end)
		else:
			res = 'No'
			break
	print(res)


N = int(input())
d = {}
for i in range(N):
	i = int(input())
	d[i] = list(map(int, input().split()))
	l = []
	while len(d[i]) > 0:
		if d[i][0] > d[i][-1]:
			l.append(d[i][0])
			d[i].pop(0)
		else:
			l.append(d[i][-1])
			d[i].pop(-1)
	flag = 0
	for j in range(len(l) - 1):
		if l[j] < l[j + 1]:
			flag = 1
	if flag == 1:
		print('No')
	else:
		print('Yes')


T = int(input())
FLAT = 0
ASC = 1
DESC = 2
for x in range(T):
	N = input()
	A = list(map(lambda x: int(x), input().split()))
	O = FLAT
	f = A[0]
	r = 'Yes'
	for x in A:
		C = FLAT
		if x > f:
			C = ASC
		elif x < f:
			C = DESC
		f = x
		if O == C:
			continue
		if O == FLAT:
			O = C
			continue
		if C == FLAT:
			continue
		if O == ASC and C == DESC:
			r = 'No'
			break
	print(r)


t = int(input())
for i in range(t):
	n = input()
	arr = [int(j) for j in input().split()]
	mn = 0
	tr = 1
	for i in range(len(arr) - 1):
		if mn == 0:
			if arr[i + 1] > arr[i]:
				mn = 1
		elif mn == 1:
			if arr[i + 1] < arr[i]:
				tr = 0
	if tr == 0:
		print('No')
	else:
		print('Yes')


tests = input()

def findout(array):
	j = 0
	k = len(array) - 1
	temp = 0
	while j <= k:
		if array[j] >= array[k] and (array[j] <= temp or temp == 0):
			temp = array[j]
			j += 1
		elif array[k] >= array[j] and (array[k] <= temp or temp == 0):
			temp = array[k]
			k -= 1
		else:
			print('No')
			return
	print('Yes')
for i in range(int(tests)):
	input()
	array = list(map(int, input().split()))
	findout(array)


tests = int(input())
for test in range(0, tests):
	count = int(input())
	cubes = list(map(int, input().split()))
	status = 'Yes'
	pile = []
	while len(cubes) > 0:
		first = cubes[0]
		last = cubes[len(cubes) - 1]
		if first >= last:
			if len(pile) > 0 and pile[len(pile) - 1] < first:
				status = 'No'
				break
			else:
				pile.append(first)
				del cubes[0]
		elif len(pile) > 0 and pile[len(pile) - 1] < last:
			status = 'No'
			break
		else:
			pile.append(last)
			del cubes[len(cubes) - 1]
	print(status)


T = int(input())
n = []
s = {}
for i in range(0, T):
	n.append(int(input()))
	s[i] = input().split()
old = []
new = []
for i in range(0, T):
	old.append([])
	new.append([])
	for j in range(0, n[i]):
		if int(s[i][0]) >= int(s[i][len(s[i]) - 1]):
			old[i].append(int(s[i][0]))
			new[i].append(int(s[i][0]))
			del s[i][0]
		else:
			old[i].append(int(s[i][len(s[i]) - 1]))
			new[i].append(int(s[i][len(s[i]) - 1]))
			del s[i][len(s[i]) - 1]
for i in range(0, T):
	new[i].sort()
	new[i].reverse()
	if old[i] == new[i]:
		print('Yes')
	else:
		print('No')


from collections import deque
t = int(input())
for i in range(t):
	n = int(input())
	cubes = deque(map(int, input().strip().split(' ')))
	stackable = 'Yes'
	last_cube = max(cubes)
	while stackable == 'Yes' and len(cubes) != 0:
		max_poppable = max(cubes[0], cubes[len(cubes) - 1])
		if cubes[0] == max_poppable and last_cube >= max_poppable:
			last_cube = cubes.popleft()
		elif cubes[len(cubes) - 1] == max_poppable and last_cube >= max_poppable:
			last_cube = cubes.pop()
		else:
			stackable = 'No'
	print(stackable)


T = int(input())
for q in range(T):
	N = int(input())
	ar = list(map(int, input().strip().split(' ')))
	base = 2 ** 32
	works = True
	while len(ar) > 0:
		e1 = ar[0]
		e2 = ar[len(ar) - 1]
		if max(e1, e2) > base:
			works = False
			break
		if e1 >= e2:
			base = ar.pop(0)
		else:
			base = ar.pop()
	if works:
		print('Yes')
	else:
		print('No')


T = int(input())
for t in range(T):
	n = int(input())
	lst = [int(x) for x in input().split()]
	prev = max(lst)
	while lst:
		if lst[-1] > lst[0]:
			if prev >= lst[-1]:
				prev = lst.pop(-1)
				n -= 1
			else:
				break
		elif prev >= lst[0]:
			prev = lst.pop(0)
			n -= 1
		else:
			break
	print('No') if n > 1 else print('Yes')


T = int(input())
for t in range(T):
	n = int(input())
	if n <= 2:
		input()
		print('Yes')
	else:
		l = list(map(int, input().split()))
		res = 'Yes'
		i = 1
		left = l[0] < l[1]
		for i in range(1, n - 1):
			if l[i] == l[i + 1]:
				continue
			right = l[i] > l[i + 1]
			if left and right:
				res = 'No'
				break
			left = not right
		print(res)


n = int(input())
for i in range(n):
	m = int(input())
	boxes = list(map(int, input().split()))
	senital = 1
	mark = 0
	i = 0
	while mark <= 1 and i <= m - 2:
		if boxes[i] * senital < boxes[i + 1] * senital:
			senital = -senital
			mark += 1
		i += 1
	if mark <= 1:
		state = 'Yes'
	else:
		state = 'No'
	print(state)


import sys
for _ in range(int(input())):
	input()
	row = list(map(int, input().strip().split(' ')))
	m = min(row)
	m_i = row.index(m)
	for x in range(m_i):
		if row[x] < row[x + 1]:
			print('No')
			break
	else:
		for x in range(m_i, len(row) - 1):
			if row[x] > row[x + 1]:
				print('No')
				break
		else:
			print('Yes')


for T in range(int(input())):
	n = int(input())
	sl = [int(i) for i in input().split()]
	if max(sl) == sl[0] or max(sl) == sl[-1]:
		print('Yes')
	else:
		print('No')


n = int(input())
for _ in range(0, n):
	input()
	li = list(map(int, input().strip().split(' ')))
	i = 0
	while i + 1 < len(li) and li[i] >= li[i + 1]:
		i += 1
	while i + 1 < len(li) and li[i] <= li[i + 1]:
		i += 1
	if i == len(li) - 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for t in range(T):
	n = int(input())
	li = list(map(int, input().split()))
	left = 0
	right = len(li) - 1
	bott = max(li)
	for i in range(len(li)):
		if li[left] >= li[right] and li[left] <= bott:
			bott = li[left]
			left = left + 1
		elif li[right] >= li[left] and li[right] <= bott:
			bott = li[right]
			right = right - 1
	if left > right:
		print('Yes')
	else:
		print('No')


n = int(input())
for _ in range(n):
	input()
	l = list(map(int, input().split()))
	i = 0
	while i < len(l):
		if i != 0 and l[i] > l[i - 1]:
			break
		i += 1
	ans = 'Yes'
	while i < len(l):
		if i != 0 and l[i] < l[i - 1]:
			ans = 'No'
			break
		i += 1
	print(ans)


from collections import deque
for _ in range(int(input())):
	input()
	d = deque((int(x) for x in input().split()))
	if d[0] < d[-1]:
		tmp = d.pop()
	else:
		tmp = d.popleft()
	while len(d) > 0:
		if tmp >= d[-1] and d[0] <= d[-1]:
			tmp = d.pop()
		elif tmp >= d[0]:
			tmp = d.popleft()
		else:
			print('No')
			d.clear()
			break
		if not len(d):
			print('Yes')


tc = int(input())
for t in range(tc):
	input()
	lst = [int(x) for x in input().split()]
	feasible = True
	i = 0
	j = len(lst) - 1
	max_so_far = max(lst[i], lst[j])
	while i <= j:
		if lst[i] > max_so_far or lst[j] > max_so_far:
			feasible = False
			break
		if lst[i] > lst[j]:
			max_so_far = max(max_so_far, lst[i])
			i += 1
		else:
			max_so_far = max(max_so_far, lst[j])
			j -= 1
	print('Yes') if feasible else print('No')


from collections import deque
T = int(input())
for t in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	d = deque(arr)
	last = float('inf')
	while d:
		(left, right) = (d[0], d[len(d) - 1])
		if left >= right and left <= last:
			last = d.popleft()
		elif right >= left and right <= last:
			last = d.pop()
		else:
			print('No')
			break
	else:
		print('Yes')


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	pre = 2 ** 32
	(a, b) = (0, len(l) - 1)
	for i in range(n):
		if l[a] > l[b]:
			num = l[a]
			a += 1
		else:
			num = l[b]
			b -= 1
		if num <= pre:
			pre = num
		else:
			return False
	return True

def main():
	t = int(input())
	for _ in range(t):
		print('Yes' if solve() else 'No')
main()


from collections import deque
from sys import exit
tests = int(input())
for t in range(0, tests):
	num_cubes = int(input())
	cube_list = deque([int(n) for n in input().split()])
	cube_stack = []
	valid = True
	if cube_list[0] >= cube_list[-1]:
		cube_stack.append(cube_list.popleft())
	else:
		cube_stack.append(cube_list.pop())
	while len(cube_list):
		if cube_list[0] >= cube_list[-1] and cube_list[0] <= cube_stack[-1]:
			cube_stack.append(cube_list.popleft())
		elif cube_list[-1] <= cube_stack[-1]:
			cube_stack.append(cube_list.pop())
		else:
			valid = False
			break
	if valid:
		print('Yes')
	else:
		print('No')


from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	if n < 3:
		print('Yes')
		continue
	d = defaultdict(list)
	maxV = lis[0]
	l_index = 0
	d['L'] = [maxV]
	for j in range(1, n):
		if lis[j] <= maxV:
			maxV = lis[j]
			d['L'].append(lis[j])
			l_index = j
		else:
			break
	if l_index < n - 1:
		maxV = lis[n - 1]
		d['R'] = [maxV]
		for j in range(n - 2, l_index, -1):
			if lis[j] <= maxV:
				maxV = lis[j]
				d['R'].append(lis[j])
			else:
				break
	if len(d['L']) + len(d['R']) == n:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(n):
	a = int(input())
	b = [int(e) for e in input().split()]
	i = 0
	j = a - 1
	height = 2 ** 31
	flag = True
	while j >= i:
		if b[i] > height or b[j] > height:
			print('No')
			flag = False
			break
		if b[i] > b[j]:
			height = b[i]
			i = i + 1
		else:
			height = b[j]
			j = j - 1
	if flag:
		print('Yes')


T = int(input())
while T > 0:
	T -= 1
	N = int(input())
	L = list(map(int, input().split()))
	l = len(L) - 1
	s = 0
	psize = max(L) + 1
	while s <= l:
		if L[s] >= L[l]:
			if L[s] <= psize:
				psize = L[s]
				s += 1
			else:
				print('No')
				break
		elif L[l] <= psize:
			psize = L[l]
			l -= 1
		else:
			print('No')
			break
	if s > l:
		print('Yes')