You are given a permutation P of length N. You can perform the following operation on P:
Choose any i and j such that i < j and P_{i} < P_{j}, and remove exactly one of them from the array. After removing, the remaining parts of the array are concatenated.

Find out if it is possible to apply the given operation any number of times such that only one element remains in the array.

Note: A permutation of length N is an array where every element from 1 to N occurs exactly once.

------ Input Format ------ 

- The first line contains T - the number of test cases. Then the test cases follow.
- The first line of each test case contains N - the length of the permutation P.
- The second line of each test case contains N space-separated integers P_{1}, P_{2}, \dots, P_{N} - elements of the permutation.

------ Output Format ------ 

For each test case, output YES if it is possible to reduce the array to a single element using the given operation. Otherwise, output NO.

You may print each character of the string in uppercase or lowercase (for example, the strings yEs, yes, Yes and YES will all be treated as identical).

------ Constraints ------ 

$1 ≤T ≤3 \cdot 10^{5}$
$1 ≤N ≤3 \cdot 10^{5}$
$1 ≤P_{i} ≤N$
$P_{1}, P_{2}, \dots, P_{N}$ form a permutation of length $N$
$\sum N$ over all test cases is at most $3 \cdot 10^{5}$

----- Sample Input 1 ------ 
3
4
3 1 2 4
3
2 3 1
6
5 2 3 6 1 4

----- Sample Output 1 ------ 
YES
NO
YES

----- explanation 1 ------ 
- Test case $1$: We can apply operations as follows (the bolded elements are the pair chosen for that operation): $
[\textbf{3}, \text{1}, \text{2}, \textbf{4}] \rightarrow
[\textbf{1}, \text{2}, \textbf{4}] \rightarrow
[\textbf{2}, \textbf{4}] \rightarrow
[\text{4}]- Test case $2$: It can be shown that it is not possible to remove all elements except one element from the array.
- Test case $3$: We can apply operations as follows: $
[\textbf{5}, \text{2}, \text{3}, \textbf{6}, \text{1}, \text{4}] \rightarrow
[\text{2}, \textbf{3}, \textbf{6}, \text{1}, \text{4}] \rightarrow
[\textbf{2}, \text{3}, \text{1}, \textbf{4}] \rightarrow
[\textbf{3}, \text{1}, \textbf{4}] \rightarrow
[\textbf{1}, \textbf{4}] \rightarrow
[\text{4}]

Difficulty: VERY_HARD

Solutions:
from sys import stdin, stdout
input = stdin.readline

class UnionFind:

	def __init__(self, n):
		self.par = [-1] * n
		self.rank = [0] * n

	def Find(self, x):
		if self.par[x] < 0:
			return x
		else:
			self.par[x] = self.Find(self.par[x])
			return self.par[x]

	def Unite(self, x, y):
		x = self.Find(x)
		y = self.Find(y)
		if x != y:
			if self.rank[x] < self.rank[y]:
				self.par[y] += self.par[x]
				self.par[x] = y
			else:
				self.par[x] += self.par[y]
				self.par[y] = x
				if self.rank[x] == self.rank[y]:
					self.rank[x] += 1

	def Same(self, x, y):
		return self.Find(x) == self.Find(y)

	def Size(self, x):
		return -self.par[self.Find(x)]
from bisect import bisect_left as lower_bound
from bisect import bisect_right as upper_bound

class FenwickTree:

	def __init__(self, x):
		bit = self.bit = list(x)
		size = self.size = len(bit)
		for i in range(size):
			j = i | i + 1
			if j < size:
				bit[j] += bit[i]

	def update(self, idx, x):
		while idx < self.size:
			self.bit[idx] += x
			idx |= idx + 1

	def __call__(self, end):
		x = 0
		while end:
			x += self.bit[end - 1]
			end &= end - 1
		return x

	def find_kth(self, k):
		idx = -1
		for d in reversed(range(self.size.bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < self.size and self.bit[right_idx] <= k:
				idx = right_idx
				k -= self.bit[idx]
		return (idx + 1, k)

class SortedList:
	block_size = 700

	def __init__(self, iterable=()):
		self.macro = []
		self.micros = [[]]
		self.micro_size = [0]
		self.fenwick = FenwickTree([0])
		self.size = 0
		for item in iterable:
			self.insert(item)

	def insert(self, x):
		i = lower_bound(self.macro, x)
		j = upper_bound(self.micros[i], x)
		self.micros[i].insert(j, x)
		self.size += 1
		self.micro_size[i] += 1
		self.fenwick.update(i, 1)
		if len(self.micros[i]) >= self.block_size:
			self.micros[i:i + 1] = (self.micros[i][:self.block_size >> 1], self.micros[i][self.block_size >> 1:])
			self.micro_size[i:i + 1] = (self.block_size >> 1, self.block_size >> 1)
			self.fenwick = FenwickTree(self.micro_size)
			self.macro.insert(i, self.micros[i + 1][0])

	def pop(self, k=-1):
		(i, j) = self._find_kth(k)
		self.size -= 1
		self.micro_size[i] -= 1
		self.fenwick.update(i, -1)
		return self.micros[i].pop(j)

	def __getitem__(self, k):
		(i, j) = self._find_kth(k)
		return self.micros[i][j]

	def count(self, x):
		return self.upper_bound(x) - self.lower_bound(x)

	def __contains__(self, x):
		return self.count(x) > 0

	def lower_bound(self, x):
		i = lower_bound(self.macro, x)
		return self.fenwick(i) + lower_bound(self.micros[i], x)

	def upper_bound(self, x):
		i = upper_bound(self.macro, x)
		return self.fenwick(i) + upper_bound(self.micros[i], x)

	def _find_kth(self, k):
		return self.fenwick.find_kth(k + self.size if k < 0 else k)

	def __len__(self):
		return self.size

	def __iter__(self):
		return (x for micro in self.micros for x in micro)

	def __repr__(self):
		return str(list(self))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) - 1 for x in input().split()]
	ob = UnionFind(n)
	all = SortedList([a[0]])
	for i in range(1, n):
		if not len(all) or all[0] > a[i]:
			all.insert(a[i])
			continue
		ob.Unite(all[0], a[i])
		while True:
			if len(all) == 1 or all[1] > a[i]:
				break
			ob.Unite(a[i], all.pop(1))
	if ob.Size(0) == n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	st = []
	m = float('inf')
	for i in arr:
		if len(st) == 0 or st[0] >= i:
			st.append(i)
			m = min(m, i)
		elif len(st) > 1:
			st.clear()
			st.append(m)
			m = float('inf')
	if len(st) != 1:
		print('NO')
	else:
		print('YES')


try:
	n = int(input())

	def check(arr):
		maxindex = 0
		maxi = arr[0]
		mini = arr[0]
		for x in range(len(arr)):
			if arr[x] > maxi:
				maxi = arr[x]
				maxindex = x
		for x in range(len(arr)):
			if arr[x] < mini and x <= maxindex:
				mini = arr[x]
		arr = [mini] + arr[maxindex + 1:]
		return arr
	for x in range(n):
		s = input()
		s1 = input()
		l1 = [int(k) for k in s1.split(' ')]
		result = False
		while result == False:
			p = len(l1)
			if len(l1) == 1:
				print('YES')
				result = True
				break
			else:
				l1 = check(l1).copy()
				if p == len(l1):
					result = True
					print('NO')
					break
				p = len(l1)
except:
	print('')


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	stck = []
	global_min = float('inf')
	for i in range(n):
		if len(stck) == 0 or stck[0] >= lst[i]:
			stck.append(lst[i])
			global_min = min(lst[i], global_min)
		elif len(stck) > 1:
			stck.clear()
			stck.append(global_min)
			global_min = float('inf')
	if len(stck) != 1:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	n = int(input())
	L = list(map(int, input().split()))
	prefix_sum = 0
	natural_suffix_sum = 0
	answer = True
	for i in range(n - 1):
		prefix_sum += L[i]
		natural_suffix_sum += n - i
		if prefix_sum == natural_suffix_sum:
			answer = False
	if answer:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	Max = arr[0]
	Min = arr[0]
	for val in arr:
		if val > Max:
			Max = Min
		elif val < Min:
			Min = val
	if Max == Min:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
input = stdin.readline

class UnionFind:

	def __init__(self, n):
		self.par = [-1] * n
		self.rank = [0] * n

	def Find(self, x):
		if self.par[x] < 0:
			return x
		else:
			self.par[x] = self.Find(self.par[x])
			return self.par[x]

	def Unite(self, x, y):
		x = self.Find(x)
		y = self.Find(y)
		if x != y:
			if self.rank[x] < self.rank[y]:
				self.par[y] += self.par[x]
				self.par[x] = y
			else:
				self.par[x] += self.par[y]
				self.par[y] = x
				if self.rank[x] == self.rank[y]:
					self.rank[x] += 1

	def Same(self, x, y):
		return self.Find(x) == self.Find(y)

	def Size(self, x):
		return -self.par[self.Find(x)]

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) - 1 for x in input().split()]
	ob = UnionFind(n)
	all = SortedList([a[0]])
	for i in range(1, n):
		if not len(all) or all[0] > a[i]:
			all.add(a[i])
			continue
		ob.Unite(all[0], a[i])
		while True:
			if len(all) == 1 or all[1] > a[i]:
				break
			ob.Unite(a[i], all.pop(1))
	if ob.Size(0) == n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mn = arr[0]
	x = arr[0]
	ptr = 0
	for i in range(n):
		if arr[i] <= x:
			mn = min(mn, arr[i])
		else:
			x = mn
			ptr = i
	print('YES' if ptr == n - 1 else 'NO')


import sys
from collections import deque

def calc(p, lst):
	stack = deque([])
	m = sys.maxsize
	for i in range(p):
		if not stack:
			stack.append(lst[i])
			m = lst[i]
		elif lst[i] < stack[-1]:
			stack.append(lst[i])
		elif lst[i] > m:
			stack = deque([stack[-1]])
			m = stack[-1]
	if len(stack) == 1:
		print('YES')
	else:
		print('NO')
n = int(input())
for i in range(n):
	p = int(input())
	lst = list(map(int, input().split()))
	calc(p, lst)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	ans = 'YES'
	for i in range(n - 1):
		s1 += l[i]
		s2 += n - i
		if s1 == s2:
			ans = 'NO'
			break
	print(ans)


from sys import stdin
input = stdin.readline

def answer():
	done = [False] * (n + 1)
	upper = n
	for i in range(1, n + 1):
		m = 0
		for j in range(d[i] + 1, upper):
			done[a[j]] = True
			m = max(m, a[j])
		for j in range(m - 1, i, -1):
			done[j] = True
		upper = min(upper, d[i])
	for i in range(2, n + 1):
		if not done[i]:
			return 'NO'
	return 'YES'
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		d[a[i]] = i
	print(answer())


from collections import deque

def hello(A):
	A = [(A[i], i) for i in range(len(A))]
	maxi = []
	mmm = 0
	for (i, j) in A[::-1]:
		mmm = max(mmm, i)
		maxi.append(mmm)
	maxi = maxi[::-1]
	A = deque(A)
	while True:
		if len(A) == 1:
			return True
		m = maxi[A[0][1]]
		mini = 100000000
		if m == A[0][0]:
			return False
		while A and A[0][0] != m:
			(ele, ind) = A.popleft()
			mini = min(mini, ele)
		if len(A) == 1:
			return True
		(ele, ind) = A.popleft()
		maxi[ind] = max(mini, maxi[ind + 1])
		A.appendleft((mini, ind))
	return True
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	if hello(A):
		print('YES')
	else:
		print('NO')


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
sys.setrecursionlimit(10 ** 8)
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	if n == 1:
		print('YES')
		continue
	pos = [0 for i in range(n + 1)]
	fl = 0
	mn = float('inf')
	mx = n
	for i in range(n):
		if a[i] == mx:
			pos[a[i]] = 1
			if a[i] < mn:
				fl = 1
				break
			temp = -1
			for j in range(n, 0, -1):
				if pos[j] == 0:
					temp = j
					break
			if temp == -1:
				break
			else:
				mx = temp
				if mx < mn:
					fl = 1
					break
		else:
			mn = min(mn, a[i])
			pos[a[i]] = 1
	if fl == 1:
		print('NO')
	else:
		print('YES')


T = int(input())
for i in range(T):
	N = int(input())
	P = list(map(int, input().split(' ')))
	P.reverse()
	temp_min = P[0]
	temp_max = P[0]
	yesval = 'yes'
	for delta in range(1, N):
		if temp_min == 1 and temp_max == delta:
			yesval = 'no'
			break
		temp_min = min(temp_min, P[delta])
		temp_max = max(temp_max, P[delta])
	if yesval == 'yes':
		print('YES')
	else:
		print('NO')


def check(a):
	mi = min(a)
	ma = max(a)
	x = a.index(mi)
	y = a.index(ma)
	if x < y:
		return [1]
	if a[0] == ma or a[-1] == mi:
		return [0]
	lmin = 10 ** 9
	for i in range(y):
		lmin = min(lmin, a[i])
	rmax = 0
	for i in range(len(a) - 1, -1, -1):
		if a[i] == mi:
			break
		rmax = max(rmax, a[i])
	a = [lmin] + a[y + 1:x] + [rmax]
	return [2, a]
t = int(input())
for _ in range(t):
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == n or n == 1 or a[0] == 1:
		print('YES')
	elif a[0] == n or a[-1] == 1:
		print('NO')
	else:
		prev = -1
		while 1:
			ok = check(a)
			if ok[0] == 1:
				fl = 0
				break
			elif ok[0] == 0:
				fl = 1
				break
			else:
				if len(ok[1]) == prev:
					fl = 1
					break
				prev = len(ok[1])
				a = ok[1][:]
		if fl ^ 1:
			print('YES')
		else:
			print('NO')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
gp = []
ans = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def flip(a, l, r):
	for i in range(l, r):
		a[i] = '0' if a[i] == '1' else '1'
	return

def hnbhai(tc):
	n = sb()
	a = sd()
	if n == 1:
		print('YES')
		return
	mn = float('inf')
	mx = n
	mark = [0] * (n + 1)
	for i in range(n):
		if a[i] == mx:
			mark[a[i]] = 1
			if a[i] < mn:
				print('NO')
				return
			ok = -1
			for j in range(n, 0, -1):
				if mark[j] == 0:
					ok = j
					break
			if ok == -1:
				break
			else:
				mx = ok
				if mx < mn:
					print('NO')
					return
		else:
			mn = min(mn, a[i])
			mark[a[i]] = 1
	print('YES')
	return
	return
for _ in range(sb()):
	hnbhai(_ + 1)


import sys, os, io
input = sys.stdin.readline
from collections import defaultdict
import bisect
import random
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	n = ii()
	a = li()
	if n == 1:
		print('YES')
		continue
	if a[-1] == 1 or a[0] == n:
		print('NO')
		continue
	if a.index(n) > a.index(1):
		print('YES')
		continue
	l = INF
	m = 0
	indn = a.index(n)
	ind1 = a.index(1)
	for i in range(indn):
		l = min(l, a[i])
	for i in range(ind1 + 1, n):
		m = max(m, a[i])
	if l < m:
		print('YES')
	else:
		x = -1
		y = -1
		for i in range(indn + 1, ind1):
			if a[i] > l:
				y = i
			if a[i] < m and x == -1:
				x = i
		if x != -1 and y != -1 and (x < y):
			print('YES')
		else:
			print('NO')


import sys
import math
import random
import heapq
input = sys.stdin.readline

def pow(a, n, m):
	if n == 0:
		return 1
	x = pow(a, n // 2, m)
	if n % 2 == 0:
		return x * x % m
	else:
		return x * x * a % m

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def bs(arr, le, ri):
	l = 0
	arr.sort()
	r = len(arr) - 1
	ans = 10000000
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= le and arr[m] <= ri:
			ans = arr[m]
			r = m - 1
		elif arr[m] < le:
			l = m + 1
		else:
			r = m - 1
	return ans

def dfs(al, l, p, n, le, pa):
	l[n] = le
	p[n] = pa
	for i in al[n]:
		if i != pa:
			dfs(al, l, p, i, le + 1, n)

def lca(al, l, p, x, y):
	if l[x] > l[y]:
		(x, y) = (y, x)
	d = l[y] - l[x]
	while d != 0:
		y = p[y]
		d -= 1
	while x != y:
		x = p[x]
		y = p[y]
	return x

def dfs1(al, i, x, y, vis, p, ans):
	vis[i] = 1
	if i == x or i == y:
		p = 1
	ans[i] = p
	for j in al[i]:
		if vis[j] == 0:
			dfs1(al, j, x, y, vis, p, ans)
l = [1] * 100001
l[0] = 0
l[1] = 0
for i in range(2, 1001):
	if l[i] == 1:
		j = i
		while j * i <= 100000:
			l[j * i] = 0
			j += 1
s = set()
s.add(1)
s.add(2)
ls = [1, 2]
for i in range(2, 500):
	for j in range(1, 100001):
		if j not in s:
			p = j
			f = 0
			for k in range(i):
				p += ls[-1 - k]
				if p % (k + 2) == 0:
					f = 1
					break
			if f == 0:
				ls.append(j)
				s.add(j)
				break
t = 1
t = int(input())
while t > 0:
	n = int(input())
	p = list(map(int, input().split()))
	for i in range(n):
		ind = -1
		mi = n + 1
		for j in range(len(p)):
			if p[j] < mi:
				mi = p[j]
				ind = j
		ma = max(p[ind:])
		if ma == mi:
			break
		else:
			p = p[:ind] + [ma]
	if len(p) == 1:
		print('YES')
	else:
		print('NO')
	t -= 1