You are given an array $a$ of length $n$, which initially is a permutation of numbers from $1$ to $n$. In one operation, you can choose an index $i$ ($1 \leq i < n$) such that $a_i < a_{i + 1}$, and remove either $a_i$ or $a_{i + 1}$ from the array (after the removal, the remaining parts are concatenated). 

For example, if you have the array $[1, 3, 2]$, you can choose $i = 1$ (since $a_1 = 1 < a_2 = 3$), then either remove $a_1$ which gives the new array $[3, 2]$, or remove $a_2$ which gives the new array $[1, 2]$.

Is it possible to make the length of this array equal to $1$ with these operations?


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 2 \cdot 10^4$)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 3 \cdot 10^5$)  — the length of the array.

The second line of each test case contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \leq a_i \leq n$, $a_i$ are pairwise distinct) — elements of the array.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3 \cdot 10^5$.


-----Output-----

For each test case, output on a single line the word "YES" if it is possible to reduce the array to a single element using the aforementioned operation, or "NO" if it is impossible to do so.


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

Output
YES
YES
NO
YES



-----Note-----

For the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):

$[\text{1}, \textbf{2}, \textbf{3}] \rightarrow [\textbf{1}, \textbf{2}] \rightarrow [\text{1}]$

$[\text{3}, \textbf{1}, \textbf{2}, \text{4}] \rightarrow [\text{3}, \textbf{1}, \textbf{4}] \rightarrow [\textbf{3}, \textbf{4}] \rightarrow [\text{4}]$

$[\textbf{2}, \textbf{4}, \text{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\textbf{4}, \textbf{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\text{4}, \text{1}, \textbf{3}, \textbf{5}] \rightarrow [\text{4}, \textbf{1}, \textbf{5}] \rightarrow [\textbf{4}, \textbf{5}] \rightarrow [\text{4}]$

Difficulty: MEDIUM

Solutions:
for a in [*open(0)][2::2]:
	a = a.split()
	print('YNEOS'[int(a[0]) >= int(a[-1])::2])


t = int(input())
a = []
for i in range(t):
	n = int(input())
	array = list(map(int, input().split(' ')))
	a.append([n, array])
for x in a:
	if x[1][0] < x[1][-1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
for _ in range(n):
	(m,) = I()
	arr = I()
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


def solve(a):
	b = []
	n = len(a)
	(minv, maxv) = (a[0], a[0])
	for i in range(1, n):
		if a[i] > a[i - 1]:
			maxv = a[i]
		else:
			b.append((minv, maxv))
			minv = a[i]
			maxv = a[i]
	b.append((minv, maxv))
	if len(b) == 1:
		return 'YES'
	return 'YES' if b[-1][1] > b[0][0] else 'NO'
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().strip().split()]
	print(solve(a))


t = int(input())
i = 0
while i < t:
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')
	i = i + 1


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


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = {}
	count = 0
	dec = 0
	f = 0
	if l[1] > l[0]:
		s[count] = [l[0]]
	else:
		s[count] = [l[0], l[0]]
		dec = 1
	for i in range(2, n):
		if dec > 0:
			if l[i] <= l[i - 1]:
				dec = 1
				count += 1
				s[count] = [l[i], l[i]]
			else:
				dec = 0
				count += 1
				s
				s[count] = [l[i - 1]]
		if dec == 0:
			if l[i] <= l[i - 1]:
				dec = 1
				s[count].append(l[i - 1])
	if dec == 0:
		s[count].append(l[-1])
	if dec == 1:
		count += 1
		s[count] = [l[-1], l[-1]]
	if f == 1:
		print('NO')
	elif len(s) == 1:
		print('YES')
	else:
		f1 = 0
		f2 = 0
		s1 = s
		s2 = s
		for (k, v) in s1.items():
			if k == len(s1) - 1:
				pass
			elif s1[k + 1][1] < s1[k][0]:
				f1 = 1
				s1[k + 1] = [s1[k][0], s1[k + 1][1]]
			else:
				s1[k + 1] = [s1[k][0], s1[k + 1][1]]
				f1 = 0
		if f1 == 1:
			print('NO')
		else:
			print('YES')


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	print('YES' * (a[-1] > a[0]) + 'NO' * (a[-1] < a[0]))


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	a = LI()
	if a[0] > a[-1]:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()][:n]
	if a[-1] > a[0]:
		print('YES')
	else:
		print('NO')


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


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	minv = []
	maxv = []
	min_v = 1000000000.0
	max_v = -1
	np = False
	for i in range(n):
		if i == 0 or ar[i] < ar[i - 1]:
			while len(minv) >= 2:
				p1 = [minv[-2], maxv[-2]]
				p2 = [minv[-1], maxv[-1]]
				minv.pop()
				minv.pop()
				maxv.pop()
				maxv.pop()
				if p2[1] > p1[0]:
					minv.append(p1[0])
					maxv.append(p2[1])
				else:
					minv += [p1[0], p2[0]]
					maxv += [p1[1], p2[1]]
					break
			min_v = ar[i]
			minv.append(min_v)
			maxv.append(ar[i])
		else:
			maxv[-1] = max(maxv[-1], ar[i])
	while len(minv) >= 2:
		p1 = [minv[-2], maxv[-2]]
		p2 = [minv[-1], maxv[-1]]
		minv.pop()
		minv.pop()
		maxv.pop()
		maxv.pop()
		if p2[1] > p1[0]:
			minv.append(p1[0])
			maxv.append(p2[1])
		else:
			np = True
			break
	if np:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	flag = True
	pre = n
	while n != 1:
		(i, j) = (0, 0)
		modify = []
		while i <= j and j < n:
			if arr[j] < arr[i]:
				modify.append([i, j - 1])
				i = j
				continue
			else:
				j += 1
				if j == n:
					modify.append([i, j - 1])
		temp = []
		l = len(modify)
		for i in range(l - 1):
			temp.append(min(arr[modify[i][0]], arr[modify[i][1]]))
		temp.append(max(arr[modify[-1][0]], arr[modify[-1][1]]))
		if len(temp) == n:
			flag = False
			break
		if len(temp) == n - 1 and max(arr) == arr[-1]:
			flag = True
			break
		elif len(temp) == n - 1:
			flag = False
			break
		arr = temp
		n = len(arr)
		if pre == n:
			flag = False
			break
		else:
			pre = n
	if flag:
		print('YES')
	else:
		print('NO')


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	minA = n + 1
	Flag = True
	for i in range(n):
		if a[i] > a[0]:
			Flag = True
		if a[i] < a[0]:
			Flag = False
	if Flag:
		print('YES')
	else:
		print('NO')


import sys
import math
from bisect import bisect_left, bisect_right

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	if a[0] > a[n - 1]:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	flag = 1
	if a[n - 1] < a[0]:
		flag = 0
	if flag:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
test = int(input().strip())
for t in range(0, test):
	n = int(input().strip())
	arr = [int(x) for x in input().strip().split()]
	if arr[-1] > arr[0]:
		print('YES')
	else:
		print('NO')
	ans = solve()


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	if l[0] < l[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis[0] > lis[-1]:
		print('NO')
	else:
		print('YES')


import sys
import math
from math import *
from collections import defaultdict
import os
from io import BytesIO, IOBase
from collections import deque

def main(d):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')
d = defaultdict(lambda : 0)
for i in range(int(input())):
	main(d)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def solve():
	n = input(11)
	a = input(1)
	out(ter(a[-1] > a[0], 'YES', 'NO'))
	return
for i in range(input(11)):
	solve()


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	res = a[0] < a[-1]
	if res:
		print('YES')
	else:
		print('NO')


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] > l[-1]:
		print('NO')
	else:
		print('YES')


I = lambda : list(map(int, input().split(' ')))

def main(lst):
	stack = []
	for i in range(len(lst)):
		if len(stack) == 0:
			stack.append(lst[i])
		elif len(stack) > 0 and stack[-1] < lst[i]:
			while len(stack) > 0 and stack[-1] < lst[i]:
				m = stack.pop()
			stack.append(m)
		else:
			stack.append(lst[i])
	if len(stack) <= 1:
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	n = int(input())
	lst = I()
	main(lst)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	smax = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		smax[i] = max(smax[i + 1], s[i])
	mn = s[0]
	ans = 'YES'
	for i in range(1, n):
		if s[i] < mn and smax[i + 1] < s[i]:
			ans = 'NO'
			break
	print(ans)


for _ in ' ' * int(input()):
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	print('YNEOS'[l[0] > l[-1]::2])


t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	if len(ls) == 1 or ls[-1] > ls[0]:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import itertools, os, sys, threading
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
from random import randrange
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def naibour_count(i, j):
	ans = 0
	if 0 < i < n - 1:
		ans += 2
	if 0 < j < m - 1:
		ans += 2
	else:
		if i in [0, n - 1] and j in [0, m - 1]:
			ans += 2
		if i in [0, n - 1]:
			ans += 3
		if j in [0, m - 1]:
			ans += 3
	return ans

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		if arr[-1] == 1 or arr[-n] == n:
			print('NO')
		elif arr[0] < arr[-1]:
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 'YES'
	if a[0] == n or a[n - 1] == 1:
		ans = 'NO'
	if a[0] > a[n - 1]:
		ans = 'NO'
	print(ans)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	key = A[0]
	f = True
	for a in A[1:]:
		if f:
			if key < a:
				pass
			else:
				f = False
		elif key < a:
			f = True
		else:
			pass
	if f:
		print('YES')
	else:
		print('NO')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	n = input()
	a = [int(x) for x in input().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		stack = []
		n = int(input())
		a = list(map(int, input().split()))
		if a[n - 1] > a[0]:
			print('YES')
		else:
			print('NO')
main()


from sys import stdin, stdout
from collections import Counter
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	a = list(I())
	print('YES' if a[0] < a[-1] else 'NO')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	if a[-1] > a[0]:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	j = n - 1
	for i in range(n - 2, -1, -1):
		if arr[i] < arr[j]:
			arr[i] = arr[j]
			j = i
	if j == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	la = []
	for i in range(n):
		la.append([-l[i], i])
	heapify(la)
	flag = 0
	while la:
		(a, b) = heappop(la)
		if b == 0:
			flag = 1
			break
		if b == n - 1:
			break
	if flag:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scanner()
	a = get_list()
	if a[-1] > a[0]:
		print('YES')
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(scanner()):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	f = 1
	mn = 100000000000
	mx = -1
	while i < j:
		mn = min(mn, a[i])
		mx = max(mx, a[j])
		if mx < mn:
			f = 0
			break
		else:
			i += 1
			j -= 1
	if f == 0:
		print('NO')
	else:
		print('YES')


input()
while True:
	try:
		n = int(input())
		p = list(map(int, input().split()))
		if p[0] > p[-1]:
			print('NO')
		else:
			print('YES')
	except EOFError:
		break
pass


cases = int(input())
for i in range(cases):
	n = int(input())
	l2 = input().split(' ')
	arr = []
	for a in l2:
		arr.append(int(a))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	if A[0] > A[n - 1]:
		print('NO')
	else:
		print('YES')
	T = T - 1


for _ in range(int(input())):
	n = int(input())
	a = [int(__) for __ in input().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for case in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	stack1 = []
	stack2 = []
	for i in range(0, n):
		if len(stack2) == 0:
			if len(stack1) > 0:
				if a[i] > stack1[-1]:
					continue
				else:
					stack2.append(a[i])
			else:
				stack1.append(a[i])
		elif a[i] > stack1[-1]:
			stack2 = []
		elif a[i] > stack2[-1]:
			stack2 = [a[i]]
		else:
			stack2.append(a[i])
	if len(stack1) > 0 and len(stack2):
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def solve():
	n = N()
	a = lis()
	if a[0] > a[n - 1]:
		NO()
	else:
		YES()
testcase(int(inp()))


def solve():
	N = int(input())
	arr = [int(x) for x in input().split()]
	if arr[0] < arr[N - 1]:
		print('YES')
	else:
		print('NO')

def main():
	t = int(input())
	while t > 0:
		solve()
		t -= 1
main()


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] > a[-1]:
		print('NO')
	else:
		print('YES')
	t -= 1


def sol():
	x = int(input())
	s = list(map(int, input().split()))
	print('YES' if s[0] < s[-1] else 'NO')
for n in range(int(input())):
	sol()


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	if a[0] <= a[-1]:
		print('YES')
	else:
		print('NO')
for i in range(mint()):
	solve()


def canBe(l):
	if l[0] < l[-1]:
		return 'YES'
	return 'NO'
test = int(input().strip())
for i in range(test):
	bleh = input()
	l = list(map(int, input().strip().split()))
	print(canBe(l))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mi = l[0]
	ma = l[-1]
	if ma > mi:
		print('YES')
	else:
		print('NO')


N = int(input())
k = 0
while k < N:
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')
	k += 1


t = int(input())
for i in range(0, t):
	impossible = 0
	n = int(input())
	a = []
	arr = []
	a = input().split(' ')
	for j in range(0, n):
		arr.append(int(a[j]))
	if arr[0] < arr[n - 1]:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	n = INI()
	X = INL()
	if X[0] < X[-1]:
		OPS('YES')
	else:
		OPS('NO')


for _ in [*open(0)][2::2]:
	_ = _.split()
	print('YNEOS'[int(_[0]) > int(_[-1])::2])


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	if A[0] < A[-1]:
		YES()
	else:
		NO()


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	t = int(stdin.readline())
	r = list(map(int, stdin.readline().split()))
	if r[0] < r[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for j in range(t):
	n = int(input())
	m = input()
	a = [int(x) for x in m.split()]
	i = 1
	left = [a[0]]
	if a[0] < a[len(a) - 1]:
		while i < len(a):
			if left[-1] < a[i]:
				while len(left) > 1 and left[-1] < a[i]:
					left.pop()
			else:
				left.append(a[i])
			i += 1
		if len(left) == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def poss(n, L):
	if L[0] == 1:
		return 'YES'
	if L[-1] == n:
		return 'YES'
	if L[0] == n:
		return 'NO'
	if L[-1] == 1:
		return 'NO'
	e = L[-1]
	f = L[0]
	if e < f:
		return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(poss(n, a))


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	Y(A[-1] > A[0])


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	n = ii()
	a = il()
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


def solve(arr):
	if arr[0] > arr[len(arr) - 1]:
		print('NO')
	else:
		print('YES')

def main():
	t = int(input())
	for i in range(t):
		input()
		arr = list(map(int, input().split()))
		solve(arr)
main()


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	print('YES' if A[0] < A[-1] else 'NO')


t = int(input())
for testcase in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if n == 1:
		print('YES')
		continue
	if A[0] < A[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input().strip())
	ar = list(map(int, input().strip().split()))
	if ar[0] < ar[-1]:
		print('YES')
	else:
		print('NO')
t = int(input().strip())
for _ in range(t):
	solve()


test = int(input())
for t in range(test):
	n = int(input())
	l = list(map(int, input().split(' ')))
	if l[0] < l[n - 1]:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import deque as que
from collections import defaultdict as vector
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	a = inar()
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(1, T + 1):
	n = int(input())
	a = [int(s) for s in input().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	a = int(input())
	z = list(map(int, input().split()))
	if z[0] > z[-1]:
		print('NO')
	else:
		print('YES')


def valeys(l):
	val = 0
	sol = []
	state = True
	for i in l:
		if state:
			if i > val:
				sol.append(val)
				state = False
		elif i < val:
			state = True
		val = i
	return sol
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	p = [int(x) for x in input().split()]
	if p[0] < p[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def ans(ar):
	if ar[-1] > ar[0]:
		return 'YES'
	else:
		return 'NO'
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(ans(a))


import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	n = I()
	l = li()
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	if k[0] > k[-1]:
		print('NO')
	else:
		print('YES')


for w in range(int(input())):
	n = int(input())
	row = list(map(int, input().strip().split()))
	if row[0] < row[-1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = int(input())
	nums = list(map(int, input().split()))
	if nums[0] < nums[-1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	stack = []
	for i in range(n):
		if not stack:
			last = -1
		else:
			last = stack[-1]
		if last > a[i]:
			stack.append(a[i])
			continue
		insert = a[i]
		while stack and stack[-1] < a[i]:
			insert = stack[-1]
			stack.pop()
		stack.append(insert)
	if len(stack) <= 1:
		print('YES')
	else:
		print('NO')


def remove_elements(permutations):
	if permutations[0] < permutations[-1]:
		return 'YES'
	return 'NO'
results = []
for _ in range(int(input())):
	_ = input()
	permutation = [int(el) for el in input().split()]
	results.append(remove_elements(permutation))
print('\n'.join(results))


import math
r = int(input())
for i in range(r):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
cases = []
for i in range(t):
	n = int(input())
	cases.append(list(map(int, input().strip().split())))

def solve(case):
	if case[0] > case[-1]:
		print('NO')
	else:
		print('YES')
for case in cases:
	solve(case)


from heapq import *
from collections import *
import os
import sys
from io import BytesIO, IOBase
import math
import bisect
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]
from fractions import Fraction as F

def main():
	store = [int(x) for x in sys.stdin.read().split()]
	t = store[0]
	x = 1
	for i in range(t):
		n = store[x]
		x += 1
		a = store[x:x + n]
		x += n
		if a[0] >= a[-1]:
			print('NO')
		else:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	found = 0
	flag = 0
	if a[-1] > a[0]:
		flag = 0
	else:
		flag = 1
	print('YES' if not flag else 'NO')


def cnt(arr):
	if arr[-1] > arr[0]:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for u in range(t):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(cnt(lst))


import os
from sys import stdin, stdout

def solve(tc):
	n = int(stdin.readline().strip())
	seq = list(map(int, stdin.readline().split()))
	if seq[0] < seq[-1]:
		print('YES')
	else:
		print('NO')
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(T,) = rl()
for _ in range(T):
	(n,) = rl()
	a = rl()
	if a[0] > a[n - 1]:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	k = int(input())
	l = list(map(int, input().split()))
	if k == 1:
		print('YES')
	elif l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	z = int(input())
	n = input().split()
	if int(n[0]) < int(n[len(n) - 1]):
		print('YES')
	else:
		print('NO')


import sys

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

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

def input():
	return sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = getN()
	arr = getList()
	if sorted(arr) == arr:
		print('YES')
		continue
	segments = [[arr[0]]]
	for i in range(n - 1):
		if arr[i + 1] > arr[i]:
			segments[-1].append(arr[i + 1])
		else:
			segments.append([arr[i + 1]])
	if min(segments[0]) < max(segments[-1]):
		print('YES')
	else:
		print('NO')


def solve(n, a):
	return 'YES' if a[n - 1] > a[0] else 'NO'
t = int(input())
for i_t in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(solve(n, a))


import heapq
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append([ls[i], i])
	arr = sorted(arr, reverse=True)
	case = 0
	nxt = n - 1
	for i in range(n - 1):
		(mn, ind) = arr[i]
		if ind == nxt:
			case = 0
			break
		elif ind == 0:
			case = 1
			break
	if case:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	n = inin()
	a = lin()
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
graph = []
visited = []
arr = []
ans = []

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		b = True
		ma_ = arr[-1]
		ind = n - 1
		end = n - 1
		for i in range(n - 2, -1, -1):
			if arr[i] < arr[end]:
				arr[i] = arr[end]
				end = i
		if end == 0:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	array = [int(x) for x in input().split()]
	yes = array[0] < array[-1]
	print('YES' * yes + 'NO' * (1 - yes))


def solve(n, ar):
	maxi = max(ar)
	mini = min(ar)
	if ar[0] == maxi or ar[-1] == mini:
		print('NO')
		return
	elif ar[0] > ar[-1]:
		print('NO')
		return
	else:
		print('YES')
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	solve(n, ar)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	if ar[-1] == 1 or ar[0] == n:
		print('NO')
	elif ar[-1] == n or ar[0] == 1:
		print('YES')
	elif ar[0] < ar[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = input()
	a = input().split()
	print(['NO', 'YES'][int(a[0]) < int(a[-1])])


for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	if arr[-1] > arr[0]:
		print('YES')
	else:
		print('NO')


tt = int(input())
for loop in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	q = [a[0]]
	for i in range(1, n):
		now = a[i]
		while len(q) > 1 and q[-1] < now:
			del q[-1]
		if now < q[-1]:
			q.append(now)
	if len(q) == 1:
		print('YES')
	else:
		print('NO')


import sys
from sys import stdin
from collections import deque, Counter
from math import factorial
from itertools import groupby

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	A = Neo()
	mini = A[0]
	flag = 0
	B = [0] * n
	p = 0
	for i in range(n - 1, -1, -1):
		p = max(A[i], p)
		B[i] = p
	for i in range(1, n):
		if A[i] <= mini:
			if B[i] <= A[i]:
				flag = 1
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	input()
	l = input().split()
	print(['NO', 'YES'][int(l[0]) < int(l[-1])])


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = [int(x) for x in input().split(' ')]
	print('NO' if l[0] > l[n - 1] else 'YES')


t = int(input())
for tc in range(t):
	n = int(input())
	arr = [int(z) for z in input().split()]
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


a = int(input())
for c in range(a):
	x = int(input())
	y = list(map(int, input().split()))
	if y[-1] < y[0]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arrar = list(map(int, input().split()))
	something = []
	t = []
	for i in range(n):
		if len(t) == 0:
			t = [arrar[i], -1]
		if len(t) != 0:
			if arrar[i] > t[1]:
				t[1] = arrar[i]
			if not arrar[i] > t[1] or i == n - 1:
				something.append(t)
				while len(something) >= 2:
					if something[-1][1] > something[-2][0]:
						something[-2][1] = something[-1][1]
						something.pop()
					else:
						break
				t = []
	if len(something) == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split(' ')))
	a = max(li)
	j = li.index(a)
	if n == 1:
		print('YES')
		continue
	if j == n - 1:
		print('YES')
		continue
	if j == 0 and n != 1:
		print('NO')
		continue
	if li[0] > li[n - 1]:
		print('NO')
		continue
	else:
		print('YES')


import sys
try:

	def main():
		n = int(input())
		l = list(map(int, input().split()))
		if l[0] < l[-1]:
			print('YES')
		else:
			print('NO')
except:
	pass
for _ in range(int(input())):
	main()


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')

def __starting_point():
	for _ in range(int(input())):
		solve()
__starting_point()


from sys import stdin
from math import ceil
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		out.append('YES')
	else:
		out.append('NO')
print('\n'.join(out))


t = int(input())
for q in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	if array[0] > array[n - 1]:
		print('NO')
	else:
		print('YES')


from sys import *
input = stdin.readline
T = int(input())
for case in range(T):
	n = int(input())
	Arr = [*map(int, input().split())]
	if Arr[0] < Arr[-1]:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	input()
	b = list(map(int, input().split()))
	print('YES' if b[0] < b[-1] else 'NO')


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		arr = [int(x) for x in input().split()]
		if arr[0] == n or arr[n - 1] == 1:
			print('NO')
		elif arr[0] > arr[-1]:
			print('NO')
		else:
			print('YES')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	lst = [int(j) for j in input().split()]
	diff = 0
	for j in range(1, n):
		diff += lst[j] - lst[j - 1]
	print('NO' if diff < 0 else 'YES')


def problemA():
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = (-1) ** i * abs(l[i])
	print(*l)

def problemB():
	(x, y) = list(map(int, input().split()))
	m = []
	for _ in range(x):
		m.append(list(map(int, input().split())))
	if m[0][0] > 2 or m[x - 1][y - 1] > 2 or m[0][y - 1] > 2 or (m[x - 1][0] > 2):
		print('NO')
		return
	for i in range(1, x - 1):
		if m[i][0] > 3 or m[i][y - 1] > 3:
			print('NO')
			return
	for i in range(1, y - 1):
		if m[0][i] > 3 or m[x - 1][i] > 3:
			print('NO')
			return
	for i in range(1, x - 1):
		for j in range(1, y - 1):
			if m[i][j] > 4:
				print('NO')
				return
	print('YES')
	m = []
	for _ in range(x):
		m.append([4] * y)
	m[0][0] = 2
	m[x - 1][y - 1] = 2
	m[x - 1][0] = 2
	m[0][y - 1] = 2
	for i in range(1, x - 1):
		m[i][0] = 3
		m[i][y - 1] = 3
	for i in range(1, y - 1):
		m[0][i] = 3
		m[x - 1][i] = 3
	for i in m:
		print(*i)

def problemC():
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')

def problemD():
	n = int(input())
	l = list(map(int, input().split()))
	c = [0] * (n + 1)
	for i in l:
		c[i] += 1
	a = []
	for _ in range(2 * n):
		i = 0
		while c[i] > 0:
			i += 1
		if i == n:
			c[l[-1]] -= 1
			l[-1] = i
			c[i] += 1
			a.append(n)
		elif i == 0:
			c[l[0]] -= 1
			l[0] = i
			c[i] += 1
			a.append(0)
		elif l[i] == i + 1:
			c[l[i - 1]] -= 1
			l[i - 1] = i
			c[i] += 1
			a.append(i)
		else:
			c[l[i]] -= 1
			l[i] = i
			c[i] += 1
			a.append(i + 1)
	print(2 * n)
	print(*a)
cases = int(input())
for _ in range(cases):
	problemC()


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	start = numbers[0]
	end = numbers[-1]
	if end < start:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	length = int(input())
	permutation = list(map(int, input().split()))
	if permutation[0] < permutation[-1]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	x = int(input())
	li = list(map(int, input().strip().split()))
	fli = []
	for i in range(1, x):
		fli.append(li[i] - li[i - 1])
	if sum(fli) < 0:
		print('NO')
	else:
		print('YES')


t = int(input())
while True:
	if t == 0:
		break
	t -= 1
	n = int(input())
	a = input()
	a = a.split()
	a = [int(i) for i in a]
	stack = []
	ind = 1
	n = len(a)
	stack.append(a[0])
	while ind < n:
		stack.append(a[ind])
		while len(stack) > 1:
			if stack[-1] - stack[-2] > 0:
				if len(stack) > 2:
					del stack[-2]
				else:
					del stack[-1]
			else:
				break
		ind += 1
	while len(stack) > 1:
		if stack[-1] - stack[-2] > 0:
			if len(stack) > 2:
				del stack[-2]
			else:
				del stack[-1]
		else:
			break
	if len(stack) > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for tc in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	q = []
	for x in a:
		if len(q) == 0:
			q.append(x)
		while len(q) >= 2 and q[-1] <= x:
			del q[-1]
		if len(q) == 1 and x > q[0]:
			continue
		else:
			q.append(x)
	print(['NO', 'YES'][int(len(q) == 1)])


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
lsc = lambda : list(input().strip('\n').split(' '))
lsi = lambda : [int(i) for i in ls()]
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	n = ii()
	l = il()
	print('YNEOS'[l[0] > l[-1]::2])


from collections import deque
for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	minI = l[0]
	flag = True
	ans = deque()
	for i in range(1, n):
		if l[i] < l[i - 1]:
			if len(ans) == 0:
				ans.append([minI, l[i - 1]])
			else:
				temp = ans.pop()
				two = [minI, l[i - 1]]
				while len(ans) > 0 and temp[0] < two[1]:
					temp = ans.pop()
				if temp[0] < two[1]:
					ans.append([temp[0], two[1]])
				else:
					ans.append(temp)
					ans.append(two)
			minI = l[i]
	if len(ans) == 0:
		ans.append([minI, l[n - 1]])
	else:
		temp = ans.pop()
		two = [minI, l[n - 1]]
		while len(ans) > 0 and temp[0] < two[1]:
			temp = ans.pop()
		if temp[0] < two[1]:
			ans.append([temp[0], two[1]])
		else:
			ans.append(temp)
			ans.append(two)
	if len(ans) > 1:
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')


from collections import deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bl
from math import log2, ceil
from heapq import heappush, heappop
from itertools import permutations

def main():
	for t in range(int(input())):
		n = int(input())
		l = [int(j) for j in input().split()]
		mn = l[0]
		fl = [False for i in range(n)]
		p = n - 1
		q = 0
		down = 0
		dn = 0
		dn_flag = False
		for i in range(1, n):
			if l[i] > l[i - 1] and (not dn_flag):
				continue
			elif l[i] > l[i - 1] and dn_flag:
				dn = max(dn, l[i])
				if dn > mn:
					dn_flag = False
			else:
				dn_flag = True
				dn = l[i]
		if mn < dn or dn_flag == False:
			print('YES')
		else:
			print('NO')
main()


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	n = inin()
	l = ain()
	f = 0
	pre = [0] * n
	prerev = [0] * n
	prerev[-1] = l[-1]
	pre[0] = l[0]
	for i in range(1, n):
		pre[i] = min(pre[i - 1], l[i])
	for i in range(n - 2, -1, -1):
		prerev[i] = max(l[i], prerev[i + 1])
	prerev.reverse()
	for i in range(n):
		if l[i] >= prerev[i] and l[i] <= pre[i]:
			print('NO')
			f = 1
			break
	if f == 0:
		print('YES')


for _ in range(int(input())):
	s = input()
	l = input().split()
	print('YES' if int(l[0]) < int(l[-1]) else 'NO')


from sys import stdin, stdout
q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	if a[0] > a[-1]:
		print('NO')
	else:
		print('YES')


import math
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if l[n - 1] > l[0]:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	line = input()
	ar = line.split()
	i = int(ar[0])
	j = int(ar[n - 1])
	if j > i:
		print('YES')
	else:
		print('NO')


MAX = 100001

def main():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		print('YES' if l[0] < l[-1] else 'NO')
main()


tc = int(input())
while tc > 0:
	tc -= 1
	n = int(input())
	k = list(map(int, input().split()))
	if k[0] > k[n - 1]:
		print('NO')
	else:
		print('YES')


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if a[-1] > a[0]:
		print('YES')
	else:
		print('NO')


from math import *
for _ in range(int(input())):
	m = int(input())
	n = list(map(int, input().split()))
	if n[-1] < n[0]:
		print('NO')
	else:
		print('YES')


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	st = [l[0]]
	for i in range(n):
		while len(st) != 1 and st[-1] < l[i]:
			st.pop()
	if len(st) == 1:
		if st[-1] > l[i]:
			st.append(l[i])
	else:
		st.append(l[i])
	if len(st) == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	m = [*map(int, input().split())]
	o = m.index(1)
	min1 = min(m[:o + 1])
	print('YES' if m[-1] > m[0] else 'NO')


from sys import stdin, stdout, setrecursionlimit
from math import ceil
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[n - 1] > a[0]:
		print('YES')
	else:
		print('NO')


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve():
	tt = I()
	for ii in range(tt):
		n = I()
		l = IL()
		if l[-1] > l[0]:
			print('YES')
		else:
			print('NO')
solve()


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	if ar[0] > ar[n - 1]:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	li = list(map(int, input().split()))
	if li[0] < li[n - 1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	stack = []
	for i in range(n):
		if not stack:
			stack.append(l[i])
		elif l[i] > stack[-1]:
			while stack and l[i] > stack[-1]:
				t = stack.pop()
			stack.append(t)
		else:
			stack.append(l[i])
	if len(stack) == 1:
		print('YES')
	else:
		print('NO')


def solve(n, a):
	if a[0] < a[-1]:
		return 'YES'
	return 'NO'

def main():
	t = int(input())
	cases = []
	for i in range(t):
		cases.append([int(input()), list(map(int, input().split()))])
	for i in cases:
		print(solve(*i))
main()


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
sys.setrecursionlimit(10 ** 5)
t = 1
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if n == 1:
		print('YES')
	else:
		print('YES' if a[0] < a[-1] else 'NO')


from sys import stdin, stdout
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	a = mp()
	summ = 0
	for i in range(1, n):
		summ += a[i] - a[i - 1]
	if summ > 0:
		cout('YES\n')
	else:
		cout('NO\n')


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(val + '\n')

def prog():
	for _ in range(int(input())):
		n = int(input())
		nums = list(map(int, input().split()))
		if nums[-1] < nums[0]:
			print('NO')
		else:
			print('YES')
prog()


ans = []
for kek in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	min = float('inf')
	max = 0
	for i in range(n):
		if a[i] < min:
			min = a[i]
		if a[i] > max:
			max = a[i]
	if a[-1] != min and a[0] != max and (a[0] < a[-1]):
		print('YES')
	else:
		print('NO')


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	list_num = list(map(int, sys.stdin.readline().split()))
	if list_num[0] > list_num[-1]:
		print('NO')
	else:
		print('YES')


import math
T = int(input())
for test in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	n = int(input())
	A = input().split(' ')
	if int(A[0]) < int(A[n - 1]):
		print('YES')
	else:
		print('NO')


import os, sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
input = sys.stdin.readline
output = []
int = int
len = len
str = str
abs = abs

def main():
	for _ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		if A[0] == 1:
			print('YES')
		elif A[0] == n:
			print('NO')
		elif A[-1] == 1:
			print('NO')
		elif A[-1] == n:
			print('YES')
		elif A[0] < A[-1]:
			print('YES')
		else:
			print('NO')
main()
sys.stdout.write('\n'.join(output))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	x = int(input())
	(*li,) = map(int, input().split())
	print('YES' if li[0] < li[-1] else 'NO')


for _ in range(int(input())):
	dlug = int(input())
	liczby = [int(x) for x in input().split()]
	if liczby[0] < liczby[-1]:
		print('YES')
	else:
		print('NO')


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] == 1:
		print('YES')
	elif l[-1] == 1:
		print('NO')
	elif l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	out(('YES', 'NO')[arr[0] > arr[-1]])


def solution(arr):
	if arr[0] < arr[-1]:
		return True
	return False
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	if solution(arr):
		print('YES')
	else:
		print('NO')


t = int(input())
for u in range(t):
	a = input()
	arr = list(map(int, input().strip().split()))
	if arr[-1] > arr[0]:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().strip().split()))
	if a[0] < a[-1]:
		stdout.write('YES' + '\n')
	else:
		stdout.write('NO' + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	list_temp = list(map(int, input().split()))
	if len(list_temp) == 1:
		print('YES')
		continue
	if list_temp[0] < list_temp[-1]:
		print('YES')
	else:
		print('NO')


import bisect
import sys
import math
input = sys.stdin.readline
import functools
from collections import defaultdict

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(case):
	n = inp()
	aa = inlt()
	stack = [aa[0]]
	reduction = aa[:]
	for i in range(1, n):
		if aa[i] <= stack[-1]:
			stack.append(aa[i])
		reduction[i] = stack[-1]
	reduction.pop()
	if aa[-1] > max(reduction):
		return 'YES'
	return 'NO'
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


from collections import deque
from math import *
import heapq
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	n = int(stdin.readline().strip())
	A = list(map(int, stdin.readline().strip().split(' ')))
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


m = int(input())
for i in range(0, m):
	n = int(input())
	mat = input().split()
	if int(mat[0]) < int(mat[-1]):
		print('YES')
	else:
		print('NO')


from math import inf as inf
from math import *
from collections import *
import sys
import os
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	seg = []
	a.append(-10000000)
	ap = []
	if a[0] < a[1]:
		inc = 1
		dec = 0
	else:
		dec = 1
		inc = 0
	for i in range(n):
		if inc:
			if a[i] < a[i + 1]:
				ap.append(a[i])
			else:
				inc = 0
				dec = 1
				seg.append(ap + [a[i]])
				ap = []
		elif a[i] > a[i + 1]:
			ap.append(a[i])
		else:
			inc = 1
			dec = 0
			seg.append(ap + [a[i]])
			ap = []
	a.pop()
	if len(ap):
		seg.append(ap)
	b = sorted(a)
	if len(seg) == 1 and b == a:
		print('YES')
		continue
	elif len(seg) == 1:
		print('NO')
		continue
	ref = min(seg[0])
	ref1 = max(seg[-1])
	flag = 0
	if flag == 0 and seg[0][0] < seg[-1][-1]:
		print('YES')
	else:
		print('NO')


def _int():
	return int(input())

def _str():
	return input()

def _list():
	return list(map(int, input().split()))
for _ in range(_int()):
	n = _int()
	l = _list()
	if l[0] < l[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
from collections import deque
input = lambda : sys.stdin.readline().strip()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')
t = int(input())
while t:
	t -= 1
	solve()


from collections import defaultdict, Counter
from math import log, ceil, floor

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = [a[0]]
	fuck = a[0]
	for i in range(1, n):
		if a[i] > fuck:
			s = [fuck]
		else:
			s.append(a[i])
	if len(s) == 1:
		print('YES')
	else:
		print('NO')
t = 1
t = int(input())
for _ in range(t):
	solve()


import io
import os
from sys import stdout
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
print = stdout.write
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	ans = 'NO\n'
	if a[0] < a[n - 1]:
		ans = 'YES\n'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	if a[0] >= a[n - 1]:
		print('NO')
	else:
		c = 0
		for i in range(1, n):
			if a[0] < a[i] and c < 0:
				c += 1
			elif a[0] >= a[i] and a[-1] <= a[i]:
				c -= 1
		if c == 0:
			print('YES')
		else:
			print('NO')


import math
import bisect
import copy
for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		n = iin()
		l = ain()
		stack = deque([])
		for i in range(n - 1, -1, -1):
			if stack == deque([]):
				stack.append(l[i])
				continue
			if stack[-1] > l[i] and len(stack) > 1:
				stack.pop()
				stack.append(l[i])
				while len(stack) > 2:
					if stack[-1] < stack[-2]:
						j = stack.pop()
						stack.pop()
						stack.append(j)
					else:
						break
				if stack[-1] < stack[-2]:
					stack.pop()
				continue
			if stack[-1] > l[i]:
				continue
			if stack[-1] < l[i]:
				stack.append(l[i])
				continue
		if len(stack) == 1:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ans = []
t = ini()
for _ in range(t):
	n = ini()
	a = inl()
	ans.append('YES' if a[0] < a[n - 1] else 'NO')
out(ans)


for i in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	cnt = 0
	if s[0] > s[-1]:
		print('NO')
	else:
		print('YES')


for z in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	if L[0] < L[n - 1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	f = 0
	x = a[0]
	a.reverse()
	m = a[0]
	a.reverse()
	if m > x:
		print('YES')
	else:
		print('NO')


from collections import deque
from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def descendents(A):
	for i in range(len(A) - 1):
		if A[i] < A[i + 1]:
			A1 = A[:]
			A2 = A[:]
			del A1[i]
			del A2[i + 1]
			return [A1, A2]
	return []

def ans_slow(A):
	work = deque([A])
	while len(work):
		A = work.popleft()
		if len(A) == 1:
			return 'YES'
		for B in descendents(A):
			work.append(B)
	return 'NO'

def ans(A):
	one_idx = A.index(1)
	if one_idx == len(A) - 1:
		if A[0] == 1:
			return 'YES'
		return 'NO'
	right_max = A[-1]
	if right_max > A[0]:
		return 'YES'
	return 'NO'
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	print(ans(A))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		rr.append(YES(a[0] <= a[-1]))
	return JA(rr, '\n')
print(main())


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	arr = LIST()
	if arr[0] < arr[n - 1]:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import deque
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	alist = stdin.readline().split()
	if len(alist) == 1 or int(alist[0]) < int(alist[-1]):
		stdout.write('YES\n')
	else:
		stdout.write('NO\n')


for item in [0] * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	stack = []
	stack.append(a[0])
	for i in range(1, n):
		if stack[len(stack) - 1] < a[i] and stack[0] < a[i]:
			for i in range(len(stack)):
				stack.pop()
			stack.append(a[0])
		elif stack[len(stack) - 1] > a[i]:
			stack.append(a[i])
	if len(stack) == 1:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	vals = list(map(int, input().split()))
	if vals[0] < vals[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())

def solve(arr):
	if arr[0] < arr[-1]:
		return 'YES'
	else:
		return 'NO'
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n + 1)
	b[1] = a[0]
	b[0] = n + 5
	cur = 1
	for i in range(1, n):
		if cur == 1:
			if a[i] > b[1]:
				pass
			else:
				b[2] = a[i]
				cur = 2
		elif b[cur] > a[i]:
			cur += 1
			b[cur] = a[i]
		else:
			b[cur] = a[i]
			while cur > 2 and b[cur] > b[cur - 1]:
				b[cur - 1] = b[cur]
				cur -= 1
			if cur == 2 and b[1] < b[2]:
				cur = 1
	if cur == 1:
		print('YES')
	else:
		print('NO')


numTests = int(input())
for test in range(numTests):
	n = int(input())
	perm = input().split(' ')
	last = int(perm[n - 1])
	first = int(perm[0])
	if first < last:
		print('YES')
	else:
		print('NO')


try:
	for _ in range(int(input())):
		n = int(input())
		arr = [int(i) for i in input().split()]
		if arr[n - 1] < arr[0]:
			print('NO')
		else:
			print('YES')
except:
	pass


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	arr = zzz()
	if arr[0] < arr[n - 1]:
		print('YES')
	else:
		print('NO')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = li()
	d = deque()
	d.append(l[-1])
	for i in range(n - 2, -1, -1):
		if l[i] < d[0]:
			while len(d) > 1 and d[0] > l[i]:
				d.popleft()
		if l[i] > d[0]:
			d.appendleft(l[i])
	print('YES' if len(d) < 2 else 'NO')


import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap
from bisect import bisect_left

@mt
def slv(N, A):
	if A[0] < A[-1]:
		return 'YES'
	else:
		return 'NO'

def main():
	a = []
	for _ in range(read_int()):
		N = read_int()
		A = read_int_n()
		a.append(slv(N, A))
	print('\n'.join(a))
main()


t = int(input())
res = []
for i in range(t):
	m = input()
	m = [int(j) for j in input().split()]
	if m[0] < m[-1]:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


tests = int(input())
for test in range(tests):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [[a[0]]]
	for i in range(1, n):
		if a[i] > a[i - 1]:
			b[-1].append(a[i])
		else:
			b.append([a[i]])
	if len(b) == 1 or b[0][0] < b[-1][-1]:
		print('YES')
	else:
		print('NO')


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(lst):
	console('----- solving ------')
	if lst[0] < lst[-1]:
		return 'YES'
	return 'NO'

def console(*args):
	return
cases = int(input())
inn = sys.stdin.readlines()
for case_num in range(cases):
	lst = list(map(int, inn[2 * case_num + 1].split()))
	res = solve(lst)
	print(res)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	mi = 10 ** 6
	pos = -1
	if a[0] == 1 or a[-1] == n:
		print('YES')
	elif a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	list1.append(-1)
	temp = []
	list2 = []
	for i in range(n):
		temp.append(list1[i])
		if list1[i + 1] < list1[i]:
			list2.append(temp)
			temp = []
	if len(list2) == 1:
		print('YES')
	else:
		a1 = min(list2[0])
		a2 = max(list2[len(list2) - 1])
		if a2 > a1:
			print('YES')
		else:
			print('NO')


def tran(arr):
	if arr[-1] > arr[0]:
		return 'YES'
	else:
		return 'NO'
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	p = tran(arr)
	ans.append(p)
for i in ans:
	print(i)


t = int(input())
for i in range(0, t):
	n = int(input())
	array = [int(j) for j in input().split(' ')]
	dif = 0
	for j in range(1, len(array)):
		dif += array[j] - array[j - 1]
	if dif > 0:
		print('YES')
	else:
		print('NO')


def answer(n, A):
	maxi = A[0]
	mini = A[0]
	if A[-1] > mini:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	print(answer(n, A))


import math

def facts(n):
	ans = [n]
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	ans = sorted(list(dict.fromkeys(ans)))
	return set(ans)
for _ in range(int(input())):
	n = int(input())
	ns = list(map(int, input().split()))
	if ns[0] < ns[-1]:
		print('YES')
	else:
		print('NO')


n = int(input())
while n > 0:
	l = int(input())
	arr = [int(x) for x in input().split()]
	stk = []
	stk.append(arr[0])
	prevs = arr[0]
	news = 0
	arr.append(0)
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i + 1]:
			while len(stk) > 1 and arr[i] > stk[-1]:
				del stk[-1]
			if arr[i] < stk[-1]:
				stk.append(prevs)
			prevs = arr[i + 1]
	if len(stk) > 1:
		print('NO')
	else:
		print('YES')
	n -= 1


def examA():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		A = LI()
		now = max(A[0], -A[0])
		cur = [now]
		for i in range(1, N):
			if i % 2 == 1:
				a = min(A[i], -A[i])
				cur.append(a)
				now = a
			else:
				a = max(A[i], -A[i])
				cur.append(a)
				now = a
		ans.append(cur)
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examB():
	T = I()
	for _ in range(T):
		(N, M) = LI()
		A = [LI() for _ in range(N)]
		flag = True
		for i in range(N):
			cell = 4
			if i == 0 or i == N - 1:
				cell -= 1
			for j in range(M):
				cell2 = deepcopy(cell)
				if j == 0 or j == M - 1:
					cell2 -= 1
				if A[i][j] > cell2:
					flag = False
					break
				A[i][j] = cell2
			if not flag:
				break
		if not flag:
			print('NO')
			continue
		print('YES')
		for v in A:
			print(' '.join(map(str, v)))
	return

def examC():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		A = LI()
		if A[0] < A[-1]:
			cur = 'YES'
		else:
			cur = 'NO'
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
from decimal import getcontext, Decimal as dec
import sys, bisect, heapq
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def I():
	return int(input())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def DI():
	return dec(input())

def LDI():
	return list(map(dec, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = dec('0.000000000001')
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(10 ** 5)
examC()


t = int(input())
while t != 0:
	t -= 1
	a = int(input())
	m = list(map(int, input().split()))
	print('YES' if m[0] < m[-1] else 'NO')


import sys
import math
from sys import stdin, stdout
from collections import deque, defaultdict
from math import ceil, floor, inf, sqrt, factorial, gcd, log2
from copy import deepcopy
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
for i in range(ii1()):
	n = ii1()
	arr = iia()
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	inp = [int(j) for j in input().split()]
	diff = 0
	for j in range(1, n):
		diff = diff + (inp[j] - inp[j - 1])
	if diff < 0:
		print('NO')
	else:
		print('YES')


import math
from collections import defaultdict

def solve():
	num = list(map(int, input().split()))
	n = len(num)
	index = n - 1
	ele = num[index]
	while index > 0:
		if num[index - 1] < ele:
			index -= 1
		elif index - 1 != 0:
			index -= 1
		else:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	n = int(input())
	solve()


from collections import defaultdict as dc
from collections import Counter
from heapq import *
import math
from bisect import bisect_left, bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 9 + 7

def sinp():
	p = str(sys, stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		if p[i] == 0:
			for j in range(2 * i, n + 1, i):
				p[i] = 1
	return p

def lower_bound(a, i, n):
	return bisect_left(a, i)

def upper_bound(a, i, n):
	return n - bisect_left(a, i)

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p

def corner(x, y, n, m):
	if x == 0 or y == 0 or x == n - 1 or (y == m - 1):
		return 1
	return 0

def solve(a, n):
	if a[0] > a[-1]:
		return 'NO'
	else:
		return 'YES'
t = inp()
for _ in range(t):
	n = inp()
	a = line()
	print(solve(a, n))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = I()
	f = 0
	cr = n
	if l[0] == n or l[-1] == 1:
		f = 1
	ar = [l[0]]
	for i in range(1, n):
		if ar[-1] > l[i]:
			ar.append(l[i])
		else:
			while len(ar) > 1 and ar[-1] < l[i]:
				ar.pop()
			ar.append(l[i])
	po = 1
	for i in range(1, len(ar)):
		if ar[0] > ar[i]:
			po = 0
	if po:
		print('YES')
		continue
	l = l[::-1]
	ar = [l[0]]
	for i in range(1, n):
		if ar[-1] < l[i]:
			ar.append(l[i])
		else:
			while len(ar) > 1 and ar[-1] > l[i]:
				ar.pop()
			ar.append(l[i])
	po = 1
	for i in range(1, len(ar)):
		if ar[i] > ar[0]:
			po = 0
	if po:
		print('YES')
		continue
	f = 1
	print('YNEOS'[f::2])


import sys
import pdb

def solve(test):
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')
test_case = 1
test_case = int(input())
for test in range(test_case):
	solve(test + 1)


from sys import stdin
a = int(stdin.readline().rstrip())
for _ in range(a):
	n = int(stdin.readline().rstrip())
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.buffer.readline
tc = int(input())
for _ in range(tc):
	n = int(input())
	lst = list(map(int, input().split()))
	if lst[0] < lst[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	ok = True
	if l[0] < l[n - 1]:
		print('YES')
	else:
		print('NO')


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] >= arr[n - 1]:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	input()
	l = input().split()
	print(['NO', 'YES'][int(l[0]) < int(l[-1])])


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	if li[-1] > li[0]:
		print('YES')
	else:
		print('NO')


inf = int(1000000.0)
t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	g = 0
	if lis[-1] > lis[0]:
		print('YES')
	elif lis[0] == 1 or lis[-1] == n:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
SI = lambda : input().strip('\n')
II = lambda : int(input())
for _ in range(II()):
	n = II()
	a = LI()
	print('YES' if a[0] < a[-1] else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

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

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

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

def main():
	n = int(input())
	arr = array()
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	main()


it = lambda : list(map(int, input().strip().split()))

def solve():
	N = int(input())
	A = it()
	return A[0] < A[N - 1]
T = int(input())
for _ in range(T):
	if solve():
		print('YES')
	else:
		print('NO')


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ch = 0
	if a[0] < a[-1]:
		ch = 1
	if ch == 0:
		stdout.write('NO\n')
	else:
		stdout.write('YES\n')


ss = []
for iii in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	if s[0] > s[-1]:
		ss.append('NO')
	else:
		ss.append('YES')
for i in ss:
	print(i)


import sys, math, random
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = []
	v = A[0]
	if A[N - 1] > v:
		print('YES')
	else:
		print('NO')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
t = int(input())
for _ in range(t):
	n = L()[0]
	A = L()
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[len(a) - 1] == 1 or a[0] == n:
		print('NO')
	elif a[len(a) - 1] > a[0]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	if ar[0] < ar[n - 1]:
		print('YES')
	else:
		print('NO')


import io
import os
from collections import Counter, defaultdict, deque
from heapq import heappush, heappop, heapify

def solve(N, A):
	mn = min(A)
	if A[0] == mn:
		return 'YES'
	heap = [(x, i) for (i, x) in enumerate(A)]
	minIndices = list(range(N))
	maxIndices = [-i for i in range(N)]
	removed = set()
	heapify(heap)
	heapify(minIndices)
	heapify(maxIndices)
	while heap:
		(x, i) = heappop(heap)
		while minIndices and minIndices[0] in removed:
			heappop(minIndices)
		while maxIndices and -maxIndices[0] in removed:
			heappop(maxIndices)
		if i == minIndices[0]:
			return 'YES'
		if i == -maxIndices[0]:
			return 'NO'
		removed.add(i)
	return 'NO'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	n = II()
	aa = LI()
	if aa[0] < aa[-1]:
		print('YES')
	else:
		print('NO')


import collections as cc
import math as mt
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')


t = int(input(''))
mat = []
for i in range(t):
	x = int(input(''))
	mat.append(list(map(int, input().split())))
for i in range(t):
	y = mat[i]
	if y[len(y) - 1] > y[0]:
		print('YES')
	else:
		print('NO')


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	n = read_int()
	A = read_ints()
	stack = [A[0]]
	for a in A[1:]:
		new_a = None
		while stack and stack[-1] < a:
			new_a = stack.pop()
		if new_a is None or new_a > a:
			stack.append(a)
		else:
			stack.append(new_a)
	return 'YES' if len(stack) == 1 else 'NO'
T = read_int()
for _ in range(T):
	print(solve())


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	n = stdint()
	arr = list(stdarr())
	if arr[-1] < arr[0]:
		print('NO')
	else:
		print('YES')


def solve():
	a = int(input())
	c = input().split()
	c = [int(x) for x in c]
	x = ''
	x = 'NO' if c[0] > c[a - 1] else 'YES'
	print(x)
t = int(input())
for i in range(t):
	solve()


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout
import sys
import operator
from decimal import Decimal
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def main():
	for _ in range(int(input())):
		n = int(input())
		a = input().split()
		if int(a[0]) > int(a[-1]):
			print('NO')
		else:
			print('YES')
main()


from sys import stdin, stdout
fi = stdin
fo = stdout
n_test = int(fi.readline())

def solve():
	n = int(fi.readline())
	a = [int(v) for v in fi.readline().split()]
	from collections import deque
	q = deque()
	for v in a:
		if not q:
			q.append(v)
			continue
		while len(q) > 1 and q[-1] < v:
			q.pop()
		if v < q[-1]:
			q.append(v)
	if len(q) < 2:
		return 'YES'
	return 'NO'
for i_test in range(n_test):
	print(solve())


import sys
import math
import bisect
from math import sqrt

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	n = iinput()
	a = get_list()
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) for a in input().split()]
	print('YES' if A[0] < A[-1] else 'NO')


def solve(arr, n, ans):
	if arr[0] < arr[-1]:
		ans.append('YES')
	else:
		ans.append('NO')

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for i in range(n - 1):
		s += l[i + 1] - l[i]
	if s <= 0:
		print('NO')
	elif s > 0:
		print('YES')


import sys
stdin = list(sys.stdin)
for i in range(1, len(stdin), 2):
	a = [int(x) for x in stdin[i + 1].split()]
	print('YES' if a[0] < a[-1] or len(a) == 1 else 'NO')


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	mi = min(l)
	if l[0] < l[len(l) - 1]:
		print('YES')
	else:
		print('NO')
	t -= 1


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	if s[0] < s[-1]:
		print('YES')
	else:
		print('NO')


from math import ceil

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		values = list(map(int, input().split()))
		minimum = -1
		for i in range(n - 1):
			if values[i] > values[i + 1] or i == n - 2:
				minimum = max(minimum, values[i])
			else:
				values[i + 1] = values[i]
		if minimum < values[-1]:
			print('YES')
		else:
			print('NO')
main()


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
fx = lambda x: 1 if x != -1 else 0
for _ in range(I()):
	n = I()
	a = L()
	print('YES' if a[0] < a[-1] else 'NO')


import math
for _ in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for hatt in range(t):
	n = int(input())
	a = [int(num) for num in input().split()]
	if a[n - 1] > a[0]:
		print('YES')
	else:
		print('NO')


import heapq
from collections import *
import math

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().strip().split()))[:n]
	if A[0] < A[n - 1]:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			n = int(R())
			a = [int(x) for x in R().split()]
			ans.append(['NO', 'YES'][a[0] < a[n - 1]])
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


t = int(input())
q = []
p = []
for i in range(t):
	e = int(input())
	y = list(map(int, input().split()))
	p.append(y)
	q.append(e)

def oe(n, arr):
	if arr[0] > arr[-1]:
		print('NO')
	else:
		print('YES')
for i in range(t):
	oe(q[i], p[i])


for _ in ' ' * int(input()):
	(n, a) = (int(input()), list(map(int, input().split())))
	print('YNEOS'[a[0] >= a[-1]::2])


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	if a[0] <= a[-1]:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	ls = get_list()
	if ls[0] > ls[-1]:
		return 'NO'
	return 'YES'

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	out = None
	mode = True
	L = 0
	R = 1
	while R < n:
		if a[L] < a[R]:
			a[R] = a[L]
			L = R
			R += 1
		else:
			R += 1
	if L == n - 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	print('YES' if arr[-1] > arr[0] else 'NO')


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	try:
		n = I()
		l = list(In())
		if l[0] < l[-1]:
			yes()
		else:
			no()
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for t in range(int(data())):
	n = int(data())
	a = mdata()
	if a[0] < a[-1]:
		out('YES')
	else:
		out('NO')


o = int(input())
for _ in range(o):
	n = int(input())
	A = list(map(int, input().split(' ')))
	dp = [None for i in range(n)]
	dp[-1] = A[-1]
	for i in range(n - 2, 0, -1):
		if A[i] < dp[i + 1]:
			dp[i] = dp[i + 1]
		else:
			dp[i] = A[i]
	done = False
	for i in range(n - 1):
		if A[i] < dp[i + 1]:
			A[i + 1] = A[i]
		else:
			done = True
			break
	if done:
		print('NO')
	else:
		print('YES')


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	points = []
	for i in range(n - 1):
		if A[i] > A[i + 1]:
			points.append(i)
	points.append(n - 1)
	m = len(points)
	if m == 1:
		print('YES')
		continue
	last_max = max(A[points[m - 2] + 1:])
	if last_max > A[0]:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [[]]
	for i in range(n - 1, 0, -1):
		if a[i] < a[i - 1]:
			b[-1].append(a[i])
			b.append([])
		else:
			b[-1].append(a[i])
	b[-1].append(a[0])
	b.reverse()
	st = [b[0][-1]]
	flag = 0
	for i in b[1:]:
		if len(st) == 1 and i[0] > st[-1]:
			continue
		elif len(st) > 1 and i[0] > st[-1]:
			while len(st) > 1 and st[-1] < i[0]:
				st.pop()
			if len(st) == 1 and st[0] > i[0]:
				st.append(i[0])
		else:
			st.append(i[-1])
	if len(st) > 1:
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	maxi = int(p[0])
	G = 0
	for j in range(1, len(p)):
		if int(p[j]) > maxi:
			G = 1
		else:
			G = 0
	if G == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split(sep=' ')))
	ans.append('YES' if nums[-1] > nums[0] else 'NO')
for i in ans:
	print(i)


for cases in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l.index(min(l)) != len(l) - 1 and l.index(max(l)) != 0 and (l[0] < l[len(l) - 1]):
		print('YES')
	else:
		print('NO')


def check():
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		arr = list(map(int, input().strip().split()))
		if arr[0] < arr[-1]:
			print('YES')
		else:
			print('NO')
check()


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		n = IP()
		arr = LS()
		stack = []
		for i in range(n):
			fg = 0
			while stack and stack[-1] < arr[i]:
				if len(stack) >= 2:
					stack.pop()
				else:
					fg = 1
					break
			if not fg:
				stack.append(arr[i])
		print('YES') if len(stack) <= 1 else print('NO')
solve()


import math
import collections
import sys

def inpu():
	return input().split(' ')

def inti(a):
	for i in range(len(a)):
		a[i] = int(a[i])
	return a

def inp():
	a = inpu()
	a = inti(a)
	return a
for _ in range(int(input())):
	n = int(input())
	a = inp()
	print(['NO', 'YES'][int(a[0]) < int(a[-1])])


def main():
	n = int(input())
	x = [int(r) for r in input().split()]
	if int(x[0]) < int(x[-1]):
		return 'YES'
	else:
		return 'NO'
num_of_cases = [int(x) for x in input().split()][0]
for p in range(num_of_cases):
	output = main()
	print('{1}'.format(p + 1, output))


for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	res = 0
	flag = 0
	for i in range(n - 1):
		res += ar[i + 1] - ar[i]
	if res < 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	st = []
	l = 2
	st = [a[0], a[1]]
	inc = 0
	dec = 0
	if a[0] > a[1]:
		dec = 1
	else:
		inc = 1
	present = dec
	for i in range(2, n):
		if l == 0:
			st.append(a[i])
		elif inc and a[i] > st[-1]:
			st.append(a[i])
			l += 1
		elif dec and a[i] < st[-1]:
			st.append(a[i])
			l += 1
		elif inc:
			while l > 1:
				if st[-2] < st[-1]:
					st.pop()
					l -= 1
				else:
					break
			st.append(a[i])
			l += 1
			while l > 1:
				if st[-2] < st[-1]:
					st.pop()
					l -= 1
				else:
					break
			if l == 1:
				inc = 1
				dec = 0
			else:
				dec = 1
				inc = 0
		else:
			while l > 1:
				if st[-1] < a[i]:
					st.pop()
					l -= 1
				else:
					break
			st.append(a[i])
			l += 1
			while l > 1:
				if st[-2] < st[-1]:
					st.pop()
					l -= 1
				else:
					break
			if l == 1:
				inc = 1
				dec = 0
			else:
				dec = 1
				inc = 0
	if len(st) == 1 or inc:
		print('YES')
	else:
		print('NO')


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = inar()
		if arr[0] < arr[-1]:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	a = lis[0]
	c = 1
	for i in range(1, a):
		if lis[-1] == i:
			print('NO')
			c = 0
			break
	if c:
		print('YES')


from collections import deque
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	seq = list(map(int, input().split()))
	print('YES' if seq[0] < seq[-1] else 'NO')


tc = int(input())
for ctr in range(tc):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis[0] < lis[-1]:
		print('YES')
	else:
		print('NO')


import sys
import random
sys.setrecursionlimit(3 * 100000 + 10)

def solve(lista: list) -> bool:
	return lista[0] < lista[-1]

def solve2(lista: list) -> bool:
	minimo_actual = lista.pop(0)
	minimos = [minimo_actual]
	for i in lista:
		if i < minimo_actual:
			minimos.append(i)
			minimo_actual = i
	for i in minimos:
		if i > lista[-1]:
			return False
	return True
for _ in range(int(input())):
	input()
	if solve2([int(x) for x in input().split(' ')]):
		print('YES')
	else:
		print('NO')


import sys

def rl():
	return sys.stdin.readline().strip()
T = int(rl())
for test in range(T):
	n = int(rl())
	a = [int(x) for x in rl().split()]
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
n = int(sys.stdin.readline().strip())
inp = []
for i in range(n):
	sys.stdin.readline()
	inp.append(sys.stdin.readline().strip().split(' '))
for each in inp:
	if int(each[-1]) < int(each[0]):
		print('NO')
	else:
		print('YES')


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]
for _ in range(r1(int)):
	n = r1(int)
	a = r2(int)
	if a[-1] < a[0]:
		print('NO')
	else:
		print('YES')


list_ans = []
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	m = max(list1[1:])
	x = list1.index(m)
	a = list1[0]
	b = list1[-1]
	if a < b:
		list_ans.append('YES')
	else:
		list_ans.append('NO')
print(*list_ans, sep='\n')


import sys

def solve(n, a):
	if a[0] < a[-1]:
		return 'YES'
	else:
		return 'NO'
take = sys.stdin.readline
for _ in range(int(take())):
	n = int(take())
	a = list(map(int, take().split()))
	result = solve(n, a)
	print(result)


tests = int(input())
while tests > 0:
	tests -= 1
	input()
	seq = list(map(int, input().split()))
	first_element = seq[0]
	single_element = True
	max = -1
	for val in seq:
		if first_element > val:
			single_element = False
			max = max if max > val else val
		elif max < val:
			single_element = True
			max = -1
	print('YES' if single_element else 'NO')


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		x = [a[n - 1]]
		for i in range(n - 2, -1, -1):
			x1 = x[-1]
			if a[i] < x1:
				while len(x) > 1 and a[i] < x[-2]:
					x.pop()
			else:
				x.append(a[i])
		if len(x) > 1:
			print('NO')
		else:
			print('YES')
if file:
	if path.exists('input1.txt'):
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for t in range(int(input())):
	input()
	lst = list(map(int, input().split()))
	if lst[0] < lst[-1]:
		print('YES')
	else:
		print('NO')


def cross_div(a):
	n = len(a)
	mn = n + 1
	mx = 0
	mnlr = []
	mxrl = []
	for i in range(n):
		if a[i] < mn:
			mn = a[i]
		mnlr.append(mn)
	for i in range(n - 1, -1, -1):
		if a[i] > mx:
			mx = a[i]
		mxrl.append(mx)
	for i in range(n):
		if mnlr[i] > mxrl[i]:
			return True
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if cross_div(a):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	s = 0
	for j in range(n - 1):
		s += lst[j + 1] - lst[j]
	if s > 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
		continue
	print('NO')


from sys import stdin, stdout
from math import gcd, log2, log10, floor
import math
from collections import defaultdict, OrderedDict
input = stdin.readline
dict = OrderedDict()
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] >= a[0]:
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	n = int(input())
	num = list(map(int, input().split()))
	if num[-1] < num[0]:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	l = RI()
	if l[0] > l[n - 1]:
		print('NO')
	else:
		print('YES')


for s in [*open(0)][2::2]:
	s = s.split()
	print('YNEOS'[int(s[0]) >= int(s[-1])::2])


t = int(input())
c = []
for i in range(t):
	n = int(input())
	a = [int(u) for u in input().split()]
	if a[0] < a[-1]:
		c.append('YES')
	else:
		c.append('NO')
for k in c:
	print(k)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	last = lst[n - 1]
	j = n - 2
	while j >= 0:
		if lst[j] < last:
			j -= 1
		else:
			break
	i = 0
	ans = 'YES'
	while i <= j:
		temp = lst[i]
		if temp > last:
			ans = 'NO'
			break
		k = i + 1
		while k <= j:
			if lst[k] > lst[i]:
				k += 1
			else:
				break
		i = k
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	if li[0] < li[-1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [abs(int(x)) for x in input().split()]
	largestStack = []
	for i in range(1, n):
		while largestStack and a[i] > largestStack[-1]:
			largestStack.pop()
		largestStack.append(a[i])
	ok = True
	for x in largestStack:
		if x < a[0]:
			print('NO')
			ok = False
			break
	if ok:
		print('YES')


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = ip()
	if x[0] < x[-1]:
		print('YES')
	else:
		print('NO')


def cast(cre, typ):
	return type(typ)(map(cre, typ))

def input_list(cre):
	return cast(cre, input().split())

def solution():
	for t in range(int(input())):
		n = int(input())
		l = input_list(int)
		print(['YES', 'NO'][0 if l[0] < l[-1] else 1])
	return
solution()


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

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

def mi():
	return map(int, input().split())

def main():
	for i in range(ii()):
		n = ii()
		l = li()
		if l[-1] > l[0]:
			print('YES')
		else:
			print('NO')
main()


def solve(n, a):
	if a[0] > a[-1]:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = [a[0]]
	m = a[0]
	for i in range(1, len(a)):
		if a[i] < s[len(s) - 1]:
			s.append(a[i])
			m = max(m, a[i])
		if a[i] == 1:
			break
	if a[len(a) - 1] > m:
		print('YES')
	else:
		print('NO')


T = input()
for i in range(0, int(T)):
	ran = input()
	ran = int(ran)
	s = input()
	s = s.split()
	if int(s[0]) < int(s[ran - 1]):
		print('YES')
	else:
		print('NO')


t = int(input())
for tc in range(t):
	n = int(input())
	line = input().split()
	if int(line[0]) < int(line[n - 1]):
		print('YES')
	else:
		print('NO')


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	n = INT()
	l = mp()
	m = [l[0]]
	for i in range(1, n):
		if l[i] <= m[0]:
			m.append(l[i])
		else:
			m = m[:1]
	if len(m) == 1:
		print('YES')
	else:
		print('NO')


from sys import stdin as std
_ = [print('YES' if arr[0] < arr[-1] else 'NO') for (n, arr) in ([int(std.readline()), list(map(int, std.readline().split()))] for y in range(int(std.readline())))]


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	suma = 0
	for i in range(n - 1):
		suma += l[i + 1] - l[i]
	if suma >= 0:
		print('YES')
	else:
		print('NO')


import math
n_case = int(input())
for i in range(n_case):
	n = int(input())
	seq = input()
	seq = [int(x) for x in seq.split()]
	if seq[0] < seq[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	block = [[]]
	prev = -1
	for item in a:
		if prev > item:
			block.append([])
		block[-1].append(item)
		prev = item
	minima = min(block[0])
	maxima = max(block[-1])
	if minima > maxima:
		print('NO')
		continue
	ok = True
	if len(block) > 2:
		for b in block[1:-1]:
			partial = False
			for item in b:
				if minima < item or item < maxima:
					partial = True
					break
			if not partial:
				ok = False
				break
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
idir = [-1, 0, 1, 0]
jdir = [0, 1, 0, -1]

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] > a[n - 1]:
		print('NO')
	else:
		print('YES')
for _ in range(t):
	solve()


def Func(n, A):
	if A[0] < A[n - 1]:
		print('YES')
	else:
		print('NO')
	return
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(j) for j in input().split()]
	Func(n, A)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	while len(arr) != 2:
		maxi = arr.index(max(arr))
		mini = arr.index(min(arr))
		if mini + 1 == len(arr) or maxi == 0:
			break
		else:
			arr = [arr[0]] + arr[maxi + 1:mini] + [arr[-1]]
	if len(arr) == 2 and arr[0] < arr[1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	dif = 0
	for i in range(1, n):
		dif += l[i] - l[i - 1]
	if dif > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	small = 10 ** 20
	if ar[0] >= ar[n - 1]:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	flag = True
	minn = 10 ** 10
	maxx = -1
	while i < j:
		minn = min(minn, a[i])
		maxx = max(maxx, a[j])
		if maxx < minn:
			flag = False
			break
		else:
			i += 1
			j -= 1
	if flag == False:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		a = inlt()
		target = a[-1]
		i = n - 2
		flag = 0
		while i >= 0:
			if a[i] >= target:
				flag = 1
				curr = a[i]
				while i >= 0:
					if a[i] < curr:
						flag = 0
						break
					i = i - 1
				if flag == 1:
					break
			else:
				i = i - 1
		if flag == 0:
			print('YES')
		else:
			print('NO')
main()


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial, cos, sin, pi
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, accumulate
from string import ascii_lowercase, ascii_uppercase
from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(I()):
	n = I()
	ls = lint()
	if ls[0] < ls[n - 1]:
		print('YES')
	else:
		print('NO')
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


import sys
input = sys.stdin.buffer.readline
from math import *
from bisect import *
import copy
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] == max(arr):
		print('NO')
	elif arr[-1] == max(arr):
		print('YES')
	elif arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
for _ in range(vary(1)):
	n = vary(1)
	num = array_int()
	if num[0] > num[-1]:
		print('NO')
	else:
		print('YES')


import sys
import math
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


import time, math, bisect, sys
sys.setrecursionlimit(100000)
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 9 + 7

def solve():
	n = II()
	li = L()
	(mn, mx) = (min(li), max(li))
	if li[-1] == mn or li[0] == mx or li[-1] < li[0]:
		print('NO')
	else:
		print('YES')
t = II()
for i in range(t):
	solve()


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def solution():
	for _ in range(Int()):
		n = Int()
		a = List()
		if a[0] < a[-1]:
			print('YES')
		else:
			print('NO')
solution()


import sys
import random
from fractions import Fraction
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

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

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	n = iinput()
	q = rlinput()
	NOYES(q[0] > q[n - 1])
for i in range(iinput()):
	main()


for i in range(int(input())):
	input()
	s = input().split()
	print(['NO', 'YES'][int(s[0]) < int(s[-1])])


from __future__ import division, print_function
import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip
MOD = 998244353
mod = 10 ** 9 + 7

def prepare_factorial(mod=mod):
	fact = [1]
	for i in range(1, 200005):
		fact.append(fact[-1] * i % mod)
	ifact = [0] * 200005
	ifact[200004] = pow(fact[200004], mod - 2, mod)
	for i in range(200004, 0, -1):
		ifact[i - 1] = i * ifact[i] % mod
	return (fact, ifact)

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, fact, ifact, MOD=mod):
	t = fact[n] * (ifact[r] * ifact[n - r]) % MOD % MOD
	return t

def get_n(Sum):
	ans = (-1 + sqrt(1 + 8 * Sum)) // 2
	return ans

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t
	return divs_number

def lrfind(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def check_sorted(a):
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			return False
	return True

def print_arr2d(a):
	for i in a:
		prr(i)

def ceil(n, k=1):
	return n // k + (n % k != 0)

def input():
	return sys.stdin.readline().strip()

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

def mi():
	return map(int, input().split())

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

def lw():
	return input().split()

def lcm(a, b):
	return abs(a * b) // gcd(a, b)

def prr(a, sep=' ', end='\n'):
	print(sep.join(map(str, a)), end=end)

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def write(s):
	return sys.stdout.write(s)

def main():
	for t in range(ii()):
		n = ii()
		a = li()
		seq = []
		temp = []
		for i in a:
			if temp == []:
				temp.append(i)
			elif i > temp[-1]:
				temp.append(i)
			else:
				if temp != []:
					seq.append(temp)
				temp = [i]
		if temp != []:
			seq.append(temp)
		if seq[0][0] < seq[-1][-1]:
			print('YES')
		else:
			print('NO')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 1000000007
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	if a[0] == 1 or a[-1] == n:
		print('YES')
	elif a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


def fast(perm):
	if perm[0] < perm[-1]:
		return 'YES'
	return 'NO'

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		perm = [int(x) for x in input().split()]
		result = fast(perm)
		print(result)
main()


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	if l[0] < l[-1]:
		pr('YES')
	else:
		pr('NO')
for _ in range(inp()):
	solve()


t = int(input())
for case in range(t):
	n = int(input())
	a = input().split()
	l = int(a[0])
	r = int(a[n - 1])
	if l <= r:
		print('YES')
	else:
		print('NO')


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1

def up(n):
	j = n - 1
	while j > 0:
		if n % j == 0:
			break
		j -= 1
	return j

def fac(n):
	c = 1
	i = 1
	while i <= n:
		c *= i
		i += 1
	return c

def check_happy(n):
	ss = set()
	print(n)
	while n != 1:
		val = n
		s = 0
		print(val)
		while val != 0:
			s += (val % 10) ** 2
			val = val // 10
		print(val)
		print('hi')
		if val in ss:
			return False
		else:
			n = val
			ss.add(n)
	return True
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	if l[0] < l[len(l) - 1]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	mi = min(l)
	if l[0] == m or l[-1] == mi or l[-1] < l[0]:
		print('NO')
	elif l[-1] == m or l[-1] > l[0] or l[0] == mi:
		print('YES')


import sys
sys.setrecursionlimit(3 * 100000 + 10)

def solve(lista: list) -> bool:
	return lista[0] < lista[-1]
	menor = lista.pop(0)
	menor_actual = menor
	mayor = menor
	for i in lista:
		if mayor < i:
			mayor = i
		if i < menor_actual:
			menor_actual = i
			mayor = menor
	return menor < mayor
for _ in range(int(input())):
	input()
	if solve([int(x) for x in input().split(' ')]):
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict

def printMat(mat):
	for i in range(len(mat)):
		mat_str = map(str, mat[i])
		print(' '.join(mat_str))

def printList(l):
	l_str = map(str, l)
	print(' '.join(l_str))

def helper(a, b, n):
	(offset, a2i, ans) = (defaultdict(int), {}, 0)
	for (i, v) in enumerate(a):
		a2i[v] = i
	for (i, v) in enumerate(b):
		off = (i - a2i[v]) % n
		offset[off] += 1
	for (off, cnt) in offset.items():
		ans = max(ans, cnt)
	return ans

def helper(nums, n):
	if nums[0] < nums[-1]:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	helper(nums, n)


def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	n = int(input())
	nums = read_list()
	if nums[0] < nums[-1]:
		print('YES')
	else:
		print('NO')


import sys
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(['NO', 'YES'][l[0] < l[n - 1]])


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def s_to_int(a):
	for i in range(len(a)):
		a[i] = int(a[i])

def factors(n):
	res = []
	t = 1
	while t * t <= n:
		if t * t == n:
			res.append(t)
		if n % t == 0:
			res.append(t)
			res.append(n // t)
		t += 1
	res.sort()
	return res

def compact_factors(n):
	res = []
	t = 2
	while t * t <= n:
		cnt = 0
		while n % t == 0:
			cnt += 1
			n //= t
		if cnt != 0:
			res.append([t, cnt])
		t += 1
	return res

def binary_search(l, target, lp, rp):
	mid = (lp + rp) // 2
	if l[mid] == target:
		return mid
	elif l[mid] > target:
		binary_search(l, target, lp, mid - 1)
	elif l[mid] < target:
		binary_search(l, target, mid + 1, rp)
	elif lp >= rp:
		return -1
n = inp()
for i in range(n):
	m = inp()
	l = inlt()
	flag = 1
	smallest = l[0]
	pivot = 0
	if l[0] > l[-1]:
		flag = 0
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list((int(num) for num in input().split()))
	if a[0] == n or a[n - 1] == 1:
		print('NO')
	else:
		p = a[0]
		c = 0
		for z in range(1, len(a)):
			if a[z] < p and c == 0:
				c = 1
			elif a[z] > p and c == 1:
				c = 0
		if c == 0:
			print('YES')
		else:
			print('NO')


for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[n - 1]
	c = 0
	for i in a:
		if i < x:
			c += 1
			print('YES')
			break
		elif i >= x:
			break
	if c == 0:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n - 1, -1, -1):
		if len(l1) == 0:
			l1.append(l[i])
			continue
		else:
			while len(l1) > 1:
				if l1[-1] > l[i]:
					l1.pop()
				else:
					break
			if l1[-1] < l[i]:
				l1.append(l[i])
	if len(l1) == 1:
		print('YES')
	else:
		print('NO')


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		N = int(input())
		P = list(map(int, input().split()))
		if P[0] < P[-1]:
			print('YES')
		else:
			print('NO')
main()


def limit(i, j):
	limitt = 4
	if i == 0:
		limitt -= 1
	if i == n - 1:
		limitt -= 1
	if j == 0:
		limitt -= 1
	if j == m - 1:
		limitt -= 1
	return limitt
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis[0] < lis[-1]:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
import math

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = input().split(' ')
		arr = list(map(int, arr))
		if arr[0] > arr[n - 1]:
			print('NO')
		else:
			print('YES')
main()


def c(arr, n):
	if arr[0] < arr[n - 1]:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(c(arr, n))


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')


def mi():
	return map(int, input().split())

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

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

def si():
	return input().split()
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	mil = []
	mi = a[0]
	for i in range(1, n):
		mil.append(mi)
		mi = min(mi, a[i])
	mi = a[n - 1]
	i = n - 2
	ma = []
	while i >= 0:
		ma.append(mi)
		mi = max(mi, a[i])
		i -= 1
	ans = 'YES'
	for i in range(n):
		if i == 0:
			if ma[i] < a[i]:
				ans = 'NO'
				break
			continue
		if i == n - 1:
			if mil[i - 1] > a[i]:
				ans = 'NO'
				break
			continue
		if mil[i - 1] > a[i] and ma[i] < a[i]:
			ans = 'NO'
			break
	print(ans)


import sys
T = int(input())
for k in range(T):
	n = int(input())
	a = [int(n) for n in input().split()]
	if a[0] < a[n - 1]:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			if a[0] < a[-1]:
				print('YES')
			else:
				print('NO')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


tests = int(input())
for case in range(tests):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	print('YES' if arr[0] < arr[n - 1] else 'NO')


tc = int(input())
for _ in range(tc):
	_ = int(input())
	xs = [int(x) for x in input().split()]
	print('YES' if xs[0] < xs[-1] else 'NO')


N = int(input())
for tests in range(N):
	arr_size = int(input())
	num = list(map(int, input().split()))
	if num[-1] < num[0]:
		print('NO')
	else:
		print('YES')


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def myceil(x, y):
	return (x + y - 1) // y

def Solution(arr, n):
	if arr[0] < arr[-1]:
		print('YES')
	else:
		print('NO')

def main():
	for _ in range(get_int()):
		n = get_int()
		arr = get_ints_in_list()
		Solution(arr, n)
main()


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))
import math

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math as M
MOD = 10 ** 9 + 7
from random import randint as R
import sys
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = [int(x) for x in input().split()]
	z = a[0]
	r = a[n - 1]
	if z < r:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	lcnt = 0
	prel = 0
	rcnt = 1
	while True:
		if rcnt >= n:
			break
		if ls[lcnt] < ls[rcnt]:
			rcnt += 1
			prel = 0
		else:
			prel += 1
			rcnt += 1
	if prel > 0:
		print('NO')
	else:
		print('YES')


import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	A = int_input()
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] > a[n - 1]:
		print('NO')
	else:
		print('YES')


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] > a[-1]:
		ans.append('NO')
	else:
		ans.append('YES')
for an in ans:
	print(an)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip()
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def case():
	n = int(input())
	a = [int(x) for x in input().split()]
	print('YES') if a[0] < a[-1] else print('NO')
t = int(input())
for _ in range(t):
	case()


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[n - 1]:
		ANS.append('YES')
	else:
		ANS.append('NO')
print('\n'.join(ANS))


def brute_force(data, l):
	check = 0
	while l != 1:
		i = 0
		while i < l - 1:
			if data[i] < data[i + 1]:
				if i > 0 and data[i - 1] < data[i + 1]:
					data.pop(i)
				else:
					data.pop(i + 1)
				check -= 1
				l -= 1
			else:
				i += 1
		check += 1
		if check > 1:
			break
	if l == 1:
		return 'YES'
	else:
		return 'NO'

def improved(data, l):
	if data[0] < data[l - 1]:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for _ in range(t):
	l = int(input())
	data = [int(d) for d in input('').split(' ')]
	print(improved(data, l))


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

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

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def primeFactors(n):
	j = []
	while n % 2 == 0:
		j.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			j.append(int(n))
			n = n / i
	if n > 2:
		j.append(int(n))
	return j

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		if a[0] > a[n - 1]:
			print('NO')
		else:
			print('YES')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	qu = [a[0]]
	for i in range(1, n):
		if a[i] < qu[len(qu) - 1]:
			qu.append(a[i])
		elif a[i] > qu[0]:
			qu = [qu[0]]
	print('YES' if len(qu) == 1 else 'NO')


import sys
import math
from collections import Counter
from collections import OrderedDict
sys.setrecursionlimit(10 ** 6)

def inputt():
	return sys.stdin.readline().strip()

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	l = listt()
	if l[0] > l[-1]:
		print('NO')
	else:
		print('YES')


z = input
for _ in range(int(z())):
	z()
	l = list(map(int, z().split()))
	print('YES' if l[0] < l[-1] else 'NO')


def find(li, ind):
	(a, b) = (1000000000.0, -1)
	for i in range(ind):
		a = min(a, li[i])
	for i in range(ind + 1, len(li)):
		b = max(b, li[i])
	return (a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	li = [int(x) for x in input().split()]
	ind = li.index(min(li))
	(l_min, r_mx) = find(li, ind)
	if li[0] > li[-1]:
		print('NO')
	elif l_min != 1000000000.0 and r_mx != -1:
		if l_min < r_mx:
			print('YES')
		else:
			print('NO')
	elif ind == 0:
		print('YES')
	else:
		print('NO')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from random import randint
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(input())
	arr = list_input()
	if arr[0] < arr[-1]:
		print('YES')
		return
	print('NO')
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

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

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a, qw):
	q = [0] * qw
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	b = [[0] * n for i in range(n)]
	for i in range(len(a)):
		for j in range(len(a)):
			b[i][j] = a[j][i]
	return b
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	print('YNEOS'[a[0] > a[-1]::2])


def main(a):
	if a[0] <= a[-1]:
		return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(main(a))


R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = R()
	A = list(R())
	print(['NO', 'YES'][A[0] < A[-1]])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
getcontext().prec = 25
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		if a[-1] > a[0]:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
input = stdin.readline

def help():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if arr[0] >= arr[-1]:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	help()


def count(a, n):
	if a[0] > a[-1]:
		return 'NO'
	else:
		return 'YES'
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = count(a, n)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = list(map(int, input().split()))
	i = ans.index(max(ans))
	if i == 0:
		print('NO')
	elif i == n - 1:
		print('YES')
	elif ans[0] < ans[-1]:
		print('YES')
	else:
		print('NO')


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	if aa[0] < aa[n - 1]:
		print('YES')
	else:
		print('NO')

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

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

def fli():
	return [float(x) for x in input().split()]

def gi():
	return [x for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
tt = fi()
while tt > 0:
	tt -= 1
	n = fi()
	a = li()
	pre = [10 ** 18 for i in range(n + 1)]
	suf = [0 for i in range(n + 1)]
	st = []
	for i in range(n):
		r = 0
		if len(st) == 0:
			st.append(a[i])
			pre[i] = a[i]
		elif st[-1] < a[i]:
			while len(st) and st[-1] < a[i]:
				if len(st) == 1:
					r = 1
					break
				st.pop()
			pre[i] = st[0]
			if r == 0:
				st.append(a[i])
		else:
			pre[i] = st[0]
			st.append(a[i])
	st = []
	for i in range(n - 1, -1, -1):
		r = 0
		if len(st) == 0:
			st.append(a[i])
			suf[i] = a[i]
		elif st[-1] > a[i]:
			while len(st) and st[-1] > a[i]:
				if len(st) == 1:
					r = 1
					break
				st.pop()
			suf[i] = st[0]
			if r == 0:
				st.append(a[i])
		else:
			suf[i] = st[0]
			st.append(a[i])
	flag = 0
	pre[n] = suf[n] = 0
	for i in range(n):
		if pre[i - 1] < a[i] and suf[i + 1] > a[i]:
			flag = 1
			break
	print('YES' if flag else 'NO')


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for t in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	stack = []
	for i in range(N):
		y = X[i]
		while stack:
			if X[i] > stack[-1]:
				if len(stack) == 1:
					y = stack[-1]
				stack.pop()
			else:
				break
		stack.append(y)
	if len(stack) == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	mas = [int(i) for i in input().split()]
	if mas[0] < mas[n - 1]:
		print('YES')
	else:
		print('NO')


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	n = int(input())
	arr = input_split()
	pending = False
	current = arr[0]
	for i in range(n - 1):
		if not pending:
			if current < arr[i + 1]:
				pass
			else:
				pending = True
				pending_val = current
				current = arr[i + 1]
		elif current < arr[i + 1]:
			current = arr[i + 1]
			if current > pending_val:
				current = pending_val
				pending = False
		else:
			pass
		if i == n - 2 and pending:
			ans = 'NO'
		else:
			ans = 'YES'
	answers.append(ans)
print(*answers, sep='\n')


def solve(n, array):
	if array[0] < array[-1]:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	n = int(input())
	array = [int(s) for s in input().split()]
	print(solve(n, array))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	block = []
	temp = [a[0]]
	for j in range(1, n):
		if a[j] > a[j - 1]:
			temp.append(a[j])
		else:
			block.append(temp)
			temp = [a[j]]
	block.append(temp)
	if min(block[0]) < max(block[-1]):
		print('YES')
	else:
		print('NO')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		arry = list(map(int, input().split()))
		currmin = arry[0]
		foundless = False
		for i in range(1, n):
			curr = arry[i]
			prev = arry[i - 1]
			if curr <= currmin:
				if not foundless:
					foundless = True
			if prev < curr:
				if foundless:
					if curr > currmin:
						foundless = False
		if not foundless:
			yield 'YES'
		else:
			yield 'NO'
t = int(input())
ans = gift()
print(*ans, sep='\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		ma = arr[n - 1]
		mi = arr[0]
		print('YES' if mi < ma else 'NO')
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	if A[0] < A[-1]:
		print('YES')
	else:
		print('NO')


I = lambda : input()
Z = lambda : int(I())
M = lambda : map(int, I().split())
for _ in range(Z()):
	n = Z()
	l = list(M())
	if n == 1 or l[-1] > l[0]:
		print('YES')
	else:
		print('NO')


import math
import os
import random
import re
import sys
from collections import Counter

def solve():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().strip().split()))
		if l[0] < l[-1] or n == 1:
			print('YES')
		else:
			print('NO')
solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] < arr[-1]:
		print('YES')
	else:
		stack = [arr[0]]
		for i in range(1, n - 1):
			if stack[-1] >= arr[i]:
				stack.append(arr[i])
		stack.append(arr[-1])
		l = len(stack)
		while l > 1 and stack[-1] > stack[-2]:
			stack.pop(-2)
			l -= 1
		if l == 1:
			print('YES')
		else:
			print('NO')


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = a[0]
	maxs = [0] * n
	maxs[n - 1] = a[n - 1]
	for x in range(n - 2, -1, -1):
		maxs[x] = max(maxs[x + 1], a[x])
	mybool = True
	for x in range(n):
		if a[x] < b and a[x] == maxs[x]:
			mybool = False
			break
	if mybool:
		stdout.write('YES\n')
	else:
		stdout.write('NO\n')


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	return a[0] < a[n - 1]

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		ws('YES' if solve(n, a) else 'NO')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	li = input()
	first = ''
	for x in li:
		if x == ' ':
			break
		else:
			first += x
	first = int(first)
	last = ''
	i = len(li) - 1
	while True:
		if li[i] == ' ':
			break
		else:
			last += li[i]
		i -= 1
	last = int(last[::-1])
	if first < last:
		print('YES')
	else:
		print('NO')


import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	n = r()
	a = rl()
	if a[0] < a[-1]:
		print('YES')
	else:
		print('NO')


import sys
import collections
inpy = [int(x) for x in sys.stdin.read().split()]
t = inpy[0]
index = 1
for _ in range(t):
	n = inpy[index]
	index += 1
	que = collections.deque()
	for i in range(n):
		x = inpy[index]
		index += 1
		if not que:
			que.append(x)
		elif len(que) == 2:
			if x > que[0]:
				que.pop()
		elif len(que) == 1:
			if x < que[0]:
				que.append(x)
	if len(que) == 1:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import Counter
from collections import defaultdict as dd
from math import sqrt, log
for t in range(int(stdin.readline().strip())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	prev = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			this = i
			b.append(a[prev:this])
			prev = this
	b.append(a[prev:n])
	b.reverse()
	m = len(b)
	i = 1
	flag = False
	for i in range(m):
		b[i].reverse()
	mx = max(b[0])
	while i < m:
		if b[i][-1] > mx:
			flag = True
			break
		for j in b[i]:
			if j < mx:
				mx = j
				break
		i += 1
	if flag:
		print('NO')
	else:
		print('YES')


for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	s = 'YES'
	i = 1
	ind = 0
	lst = []
	lst1 = []
	while i <= n - 1:
		if a[i] <= a[i - 1]:
			lst.append(a[ind])
			lst1.append(a[i - 1])
			ind = i
		i += 1
	lst.append(a[ind])
	lst1.append(a[n - 1])
	ln = len(lst)
	print('NO' if lst[0] > lst1[-1] else 'YES')


from math import *
from random import *

def compr(mas):
	n = len(mas)
	mn = []
	mx = []
	cr = [mas[0]]
	for i in range(1, n):
		if mas[i] > mas[i - 1]:
			cr.append(mas[i])
		else:
			mn.append(cr[0])
			mx.append(cr[-1])
			cr = [mas[i]]
	if len(cr) > 0:
		mn.append(cr[0])
		mx.append(cr[-1])
	return mn[:-1:1] + [mx[-1]]
for t in range(int(input())):
	n = int(input())
	mass = list(map(int, input().split()))
	cr = [mass[0]]
	for i in range(1, n):
		if mass[i] > cr[0]:
			cr = [cr[0]]
		else:
			cr.append(mass[i])
	if len(cr) == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for f in range(int(input())):
	n = int(input())
	p = list(map(int, input().split()))
	if p[0] > p[-1]:
		print('NO')
	else:
		print('YES')


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

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

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

def brute(a):
	n = len(a)
	if n == 1:
		return True
	for i in range(0, n - 1):
		if a[i] < a[i + 1]:
			tmp = brute(a[:i + 1] + a[i + 2:]) or brute(a[:i] + a[i + 1:])
			if tmp:
				return True
	return False
from itertools import permutations

def main():
	t = ii()
	for _ in range(t):
		n = ii()
		a = lii()
		if a[0] < a[n - 1]:
			print('YES')
		else:
			print('NO')
main()


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(x) for x in sys.stdin.readline().split()]
	if a[0] < a[-1]:
		ans_arr.append(str('YES'))
	else:
		ans_arr.append(str('NO'))
print('\n'.join(ans_arr))