For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?

Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it!  

Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.

For completing the chamber Wheatley needs $n$ cubes. $i$-th cube has a volume $a_i$.

Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $i>1$, $a_{i-1} \le a_i$ must hold.

To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $i>1$ you can exchange cubes on positions $i-1$ and $i$.

But there is a problem: Wheatley is very impatient. If Wheatley needs more than $\frac{n \cdot (n-1)}{2}-1$ exchange operations, he won't do this boring work.

Wheatly wants to know: can cubes be sorted under this conditions?


-----Input-----

Each test contains multiple test cases.

The first line contains one positive integer $t$ ($1 \le t \le 1000$), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains one positive integer $n$ ($2 \le n \le 5 \cdot 10^4$) — number of cubes.

The second line contains $n$ positive integers $a_i$ ($1 \le a_i \le 10^9$) — volumes of cubes.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise.


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

Output
YES
YES
NO



-----Note-----

In the first test case it is possible to sort all the cubes in $7$ exchanges.

In the second test case the cubes are already sorted.

In the third test case we can make $0$ exchanges, but the cubes are not sorted yet, so the answer is "NO".

Difficulty: EASY
Tags: Sorting

Mathematics
Skill types: Sorting

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	flag = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			flag = True
			break
	print('YES' if flag is True else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n == len(set(l)) and l[::-1] == sorted(l):
		print('NO')
	else:
		print('YES')


def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if countSwaps(a, n) > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	limit = n * (n - 1) / 2 - 1
	d = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			d += 1
		else:
			status = 'YES'
	if d == n - 1:
		status = 'NO'
	print(status)


t = int(input())
for i in range(t):
	n = int(input())
	lst = [int(x) for x in input().split()]
	f = False
	for i in range(1, n):
		if lst[i] >= lst[i - 1]:
			f = True
	print('YES' if f == True else 'NO')


t = int(input())
while t > 0:
	t -= 1
	d = True
	n = int(input())
	a = list(map(int, input().strip().split()))
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			d = False
			break
	if d == True:
		print('NO')


import sys
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	cubes = [int(num) for num in sys.stdin.readline().split()]
	possible = False
	for i in range(1, len(cubes)):
		if cubes[i] >= cubes[i - 1]:
			print('YES')
			possible = True
			break
	if not possible:
		print('NO')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = sorted(a, reverse=True)
	if a == b and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


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


import sys
t = int(input())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	can = False
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')


def count_inversions(a):
	res = 0
	counts = [0] * (len(a) + 1)
	rank = {v: i + 1 for (i, v) in enumerate(sorted(a))}
	for x in reversed(a):
		i = rank[x] - 1
		while i:
			res += counts[i]
			i -= i & -i
		i = rank[x]
		while i <= len(a):
			counts[i] += 1
			i += i & -i
	return res
t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	inv = count_inversions(a)
	lim = n * (n - 1) / 2 - 1
	if inv > lim:
		print('NO')
	else:
		print('YES')


def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	check = n * (n - 1) // 2 - 1
	result = mergeSort(arr, n)
	if result <= check:
		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, log
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(str(var) + end)

def outa(*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)]

def getSum(BITree, index):
	s = 0
	while index > 0:
		s += BITree[index]
		index -= index & -index
	return s

def updateBIT(BITree, n, index, val):
	while index <= n:
		BITree[index] += val
		index += index & -index

def convert(arr, n):
	temp = [0] * n
	for i in range(n):
		temp[i] = arr[i]
	temp.sort()
	for i in range(n):
		arr[i] = bl(temp, arr[i]) + 1

def findElements(arr, n):
	convert(arr, n)
	BIT = [0] * (n + 1)
	smaller_right = [0] * n
	for i in range(n - 1, -1, -1):
		smaller_right[i] = getSum(BIT, arr[i] - 1)
		updateBIT(BIT, n, arr[i], 1)
	return sum(smaller_right)
for _ in range(int(data())):
	n = int(data())
	arr = l()
	if findElements(arr, n) > n * (n - 1) // 2 - 1:
		out('NO')
		continue
	out('YES')


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	B = [A[i] > A[i + 1] for i in range(n - 1)]
	if all(B):
		print('NO')
	else:
		print('YES')
for t in range(int(input())):
	f()


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


t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))[:n]
	val = n * (n - 1) / 2 - 1
	i = 0
	count = 0
	while i < n - 1:
		if list1[i] > list1[i + 1]:
			count += 1
		i += 1
	if count < n - 1:
		print('YES')
	else:
		print('NO')


import bisect

def invNumCount(A):
	N = len(A)
	res = 0
	BIT = [0] * (N + 1)

	def BIT_query(idx):
		res_sum = 0
		while idx > 0:
			res_sum += BIT[idx]
			idx -= idx & -idx
		return res_sum

	def BIT_update(idx, x):
		while idx <= N:
			BIT[idx] += x
			idx += idx & -idx
		return
	B = sorted(A)
	for (i, e) in enumerate(A):
		A[i] = bisect.bisect_left(B, e)
	for (i, e) in enumerate(A):
		res += i - BIT_query(e + 1)
		BIT_update(e + 1, 1)
	return res
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if invNumCount(a) < n * (n - 1) // 2:
		print('YES')
	else:
		print('NO')


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


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = l.copy()
	o.sort(reverse=True)
	if l == o and len(set(l)) == n:
		print('NO')
		continue
	print('YES')


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	dem = 0
	for x in range(0, n - 1):
		dem += a[x] > a[x + 1]
	print(['YES', 'NO'][dem == n - 1])


test = int(input())
for i in range(test):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	a1 = list(set(a))
	l = len(a1)
	a2 = sorted(a, reverse=True)
	if a2 == a and l == n:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = sorted(a, reverse=True)
	k = list(dict.fromkeys(a))
	if len(k) == len(a):
		if a == b:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


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


for i in range(int(input())):
	l = int(input())
	p = [int(x) for x in input().split()]
	a = p.copy()
	a.sort(reverse=True)
	if a == p and len(set(p)) == l:
		print('NO')
	else:
		print('YES')


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')
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a == sorted(a, reverse=True) and len(set(a)) == n:
		print('No')
	else:
		print('Yes')


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = a[:]
	t = list(set(t))
	if len(t) != len(a):
		f = 1
	else:
		f = 0
	if a == sorted(a, reverse=True) and f == 0:
		print('NO')
	else:
		print('YES')


num_test = int(input())

def reversed(l):
	for i in range(0, len(l) - 1):
		if l[i] <= l[i + 1]:
			return False
	return True
for i in range(0, num_test):
	n = int(input())
	l1 = input().split(' ')
	l = []
	for el in l1:
		l.append(int(el))
	if reversed(l):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))

	def countSwaps(l, n):
		a = [0] * n
		return merge_Sort(l, a, 0, n - 1)

	def sort(l, a, le, m, r):
		count = 0
		i = le
		j = m
		k = le
		while i <= m - 1 and j <= r:
			if l[i] <= l[j]:
				a[k] = l[i]
				k += 1
				i += 1
			else:
				a[k] = l[j]
				k += 1
				j += 1
				count = count + (m - i)
		while i <= m - 1:
			a[k] = l[i]
			k += 1
			i += 1
		while j <= r:
			a[k] = l[j]
			k += 1
			j += 1
		for i in range(le, r + 1, 1):
			l[i] = a[i]
		c = count
		return c

	def merge_Sort(l, a, le, r):
		count = 0
		if r > le:
			m = int((r + le) / 2)
			count = merge_Sort(l, a, le, m)
			count += merge_Sort(l, a, m + 1, r)
			count += sort(l, a, le, m + 1, r)
		return count
	s = countSwaps(l, n)
	d = n * (n - 1) / 2
	if s > d - 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if all((x > y for (x, y) in zip(a, a[1:]))):
		print('NO')
	else:
		print('YES')


t = int(input())
for m in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	accept = False
	for i in range(n):
		b.append(a[i])
	b.sort()
	b.reverse()
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			accept = True
	if accept:
		print('YES')
	elif a == b:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	k = [int(j) for j in input().split()]
	flag = 0
	for i in range(1, n):
		if k[i] >= k[i - 1]:
			flag = 1
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	input()
	l = list(map(int, input().split()))
	print('yneos'[l == sorted(l, reverse=True) and len(set(l)) == len(l)::2])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(a)
	b.sort(reverse=True)
	sa = set(a)
	if len(sa) == len(a) and a == b:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sorted_a = sorted(a, reverse=True)
	cnt = len(set(a))
	if a == sorted_a and cnt == n:
		print('NO')
	else:
		print('YES')


from sys import stdin

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

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

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

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = (right + left) // 2
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
t = iinput()
while t:
	t -= 1
	n = iinput()
	arr = linput()
	opp = countSwaps(arr, n)
	req = n * (n - 1) // 2 - 1
	print('YES' if opp <= req else 'NO')


import sys
import copy
T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	B = copy.deepcopy(A)
	B.sort(reverse=True)
	if len(set(A)) == len(B) and A == B:
		print('NO')
	else:
		print('YES')
	T = T - 1


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


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math
import heapq
import re

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()
		a = ain()
		asc = sorted(a)
		desc = sorted(a, reverse=True)
		if asc == a:
			print('YES')
		elif desc == a and n == len(set(a)):
			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')
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()


for __ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	flag = False
	for i in range(1, len(arr)):
		if arr[i] >= arr[i - 1]:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for (x, y) in zip(a, a[1:]):
		if x <= y:
			print('Yes')
			break
	else:
		print('No')


def solution(n, cubes):
	ok = True
	for i in range(n - 1):
		ok = ok and cubes[i] > cubes[i + 1]
	if ok:
		return 'NO'
	else:
		return 'YES'
t = int(input())
while t > 0:
	n = int(input())
	cubes = list(map(int, input().split(' ')))
	print(solution(n, cubes))
	t -= 1


for _ in range(int(input())):
	c = 0
	n = int(input())
	l = [int(i) for i in input().split()]
	ls = sorted(l, reverse=True)
	if ls == l and len(l) == len(set(l)):
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
n = int(input())
while n > 0:
	k = int(input())
	a = list(map(int, input().split()))
	if len(a) == len(set(a)) and a[::-1] == sorted(a):
		print('NO')
	else:
		print('YES')
	n = n - 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	p = sorted(a, reverse=True)
	s = set()
	for i in a:
		s.add(i)
	if p == a and len(s) == len(a):
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:]
	b.sort(reverse=True)
	flag = False
	for i in range(n):
		if a[i] != b[i]:
			flag = True
	if flag or len(set(a)) < len(a):
		print('YES')
	else:
		print('NO')


def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for i in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	if countSwaps(arr, n) > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	for (c, d) in zip(a, a[1:]):
		if c <= d:
			print('YES')
			return
	print('NO')
	return
t = int(input())
for i in range(t):
	solve()


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		x = l.copy()
		ch = l.copy()
		ch = ch[::-1]
		x.sort()
		z = 0
		if n == 1:
			print('YES')
		elif x == ch:
			if len(set(x)) < n:
				print('YES')
			else:
				print('NO')
		else:
			print('YES')
except:
	print(sys.exc_info[0])
	pass


import itertools
import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1\n\n\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield input()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]

def solve(a):
	_min = a[0]
	for i in range(1, len(a)):
		if a[i] >= _min:
			return 'YES'
		_min = min(_min, a[i])
	return 'NO'
t = getType(int)
for _ in range(t):
	n = getType(int)
	a = getArray(int)
	res = solve(a)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = sorted(l, reverse=True)
	if l == k and len(set(k)) == n:
		print('NO')
	else:
		print('YES')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	ch = n * (n - 1) // 2 - 1
	p = a.copy()
	p.sort(reverse=True)
	if p == a and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	L = list(map(int, input().split(' ')))
	found = False
	j = 0
	while j < n - 1 and (not found):
		if L[j] <= L[j + 1]:
			found = True
		j += 1
	if found == False:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	a = int(input())
	l = [int(i) for i in input().split()]
	check = False
	for i in range(a - 1):
		if l[i] == l[i + 1]:
			check = True
			break
	if check:
		print('YES')
		continue
	x = sorted(l, reverse=True)
	print('YES' if l != x else 'NO')


t = int(input())
l = []
for i in range(t):
	n = int(input())
	v = list((int(x) for x in input().split()))
	l.append(v)
for i in range(t):
	c = 0
	n = len(l[i])
	for j in range(n - 1):
		if l[i][j] <= l[i][j + 1]:
			c = 1
			break
	if c == 1:
		print('YES')
	else:
		print('NO')


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


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


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


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(i) for i in input().split()]
	flag = 1
	for i in range(1, n):
		if arr[i - 1] > arr[i]:
			continue
		else:
			print('YES')
			flag = 0
			break
	if flag:
		print('NO')
	t -= 1


for t in range(int(input())):
	l = int(input())
	tk = list(map(int, input().split()))
	print('NO' if l == len(set(tk)) and tk == sorted(tk, reverse=True) else 'YES')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

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()
	for i in range(n - 1):
		if ls[i] <= ls[i + 1]:
			return 'YES'
	return 'NO'

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


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().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
from itertools import permutations as permu

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 = 1
num = int(z())
for _ in range(num):
	n = int(z())
	arr = zz()
	if sorted(arr)[::-1] == arr and sorted(arr) != arr and (len(set(arr)) == len(arr)):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	if a == sorted(a)[::-1] and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


def Solve(arr, n):
	if n == 1:
		return 'YES'
	for i in range(1, n):
		if arr[i - 1] <= arr[i]:
			return 'YES'
	return 'NO'
T = int(input())
for i in range(T):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	res = Solve(arr, n)
	print(res)


for i in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	b = s.copy()
	b.sort(reverse=True)
	if s != b or len(set(s)) != n:
		print('YES')
	else:
		print('NO')


def solve(arr):
	for i in range(len(arr) - 1):
		if arr[i] <= arr[i + 1]:
			return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	print(solve(s))


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


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


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

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for _ in range(vary(1)):
	n = vary(1)
	arr = array_int()
	if countSwaps(arr, n) > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


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


for _ in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	y = sorted(x)
	x = x[::-1]
	if len(set(x)) == n and y == x:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	k = sorted(a, reverse=True)
	if a != k:
		print('YES')
	else:
		tle = len(set(k))
		if tle * (tle - 1) // 2 <= n * (n - 1) // 2 - 1:
			print('YES')
		else:
			print('NO')


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	col = n * (n - 1) // 2 - 1
	cur = 0
	for i in range(1, n):
		if a[i - 1] > a[i]:
			cur += 1
			col -= cur
		else:
			cur = 0
	if col < 0:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = (right + left) // 2
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	swp = countSwaps(a, n)
	lim = n * (n - 1) // 2 - 1
	print('YES' if swp <= lim else 'NO')


import collections

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


t = input()
t = int(t)
for i in range(t):
	n = input()
	n = int(n)
	s = input().split()
	l = []
	m = []
	var = int(s[1])
	count = 1
	for j in range(len(s)):
		l.append(int(s[j]))
		m.append(int(s[j]))
	m.sort(reverse=True)
	for k in range(len(m) - 1):
		if m[k] == m[k + 1]:
			count = 0
	if count == 0:
		print('YES')
		continue
	if l == m:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	check = False
	for i in range(n - 1, 0, -1):
		if a[i] >= a[i - 1]:
			check = True
			break
	if not check:
		print('NO')
	else:
		print('YES')


import sys
for i in range(0, int(sys.stdin.readline())):
	g = sys.stdin.readline()
	l = list(map(int, sys.stdin.readline().split()))
	works = 'NO'
	for j in range(0, len(l) - 1):
		if l[j + 1] >= l[j]:
			works = 'YES'
	sys.stdout.write(works + '\n')


t = int(input())
ars = []
for t_ in range(t):
	n = int(input())
	vals = list(map(int, input().split(' ')))
	it_can = True
	for n_ in range(1, len(vals)):
		if vals[n_] >= vals[n_ - 1]:
			break
	else:
		it_can = False
	ars.append(it_can)
for i in range(len(ars)):
	if ars[i]:
		print('YES')
	else:
		print('NO')


for x in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == len(set(l)) and l == sorted(l, reverse=True):
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = sorted(a)
	z = len(set(a))
	if a == x[::-1] and z == n:
		print('NO')
	else:
		print('YES')


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


def mergeSort(array):
	if len(array) == 1:
		return 0
	mid = len(array) // 2
	left = array[:mid]
	right = array[mid:]
	ans = mergeSort(left)
	ans += mergeSort(right)
	(i, j, k) = (0, 0, 0)
	while i < len(left) and j < len(right):
		if left[i] <= right[j]:
			array[k] = left[i]
			i += 1
		else:
			ans += len(left) - i
			array[k] = right[j]
			j += 1
		k += 1
	while i < len(left):
		array[k] = left[i]
		i += 1
		k += 1
	while j < len(right):
		array[k] = right[j]
		j += 1
		k += 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if mergeSort(l) <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from typing import List
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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())

@lru_cache(None)
def fact(x, mod=0):
	if x < 2:
		return 1
	if not mod:
		return fact(x - 1) * x
	return fact(x - 1, mod) * x % mod

@lru_cache(None)
def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	ans = 1
	for k in range(i - j + 1, i + 1):
		ans = ans * k % mod
	return ans

@lru_cache(None)
def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j) * inverse(fact(j), mod) % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	n = N()
	a = RLL()
	b = sorted(a, reverse=True)
	ans = 'YES' if a != b or any((a[i] == a[i - 1] for i in range(1, n))) else 'NO'
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	MX = N * (N - 1) // 2 - 1
	if A == sorted(A)[::-1] and len(set(A)) == N:
		return 'NO'
	else:
		return 'YES'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


l = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) < n:
		l.append('YES')
	else:
		flag = 1
		for i in range(n - 1):
			if a[i] < a[i + 1]:
				flag = 1
				break
			else:
				flag = 0
		if flag == 1:
			l.append('YES')
		else:
			l.append('NO')
for i in l:
	print(i)


def is_less_than_specified(l, n):
	c = []
	for i in l:
		if i in c:
			return 'YES'
		c.append(i)
	t = sorted(l, reverse=True)
	if l != t:
		ans = 'YES'
	else:
		ans = 'NO'
	return ans
t = int(input())
for k in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(is_less_than_specified(l, n))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = False
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			flag = True
			break
	print('YES' if flag == True else 'NO')


def main(arr):
	if len(arr) == 1:
		return True
	previous_value = arr[0]
	for (index, item) in enumerate(arr[1:]):
		if item >= previous_value:
			return True
		previous_value = arr[index + 1]
	return False
tt = int(input())
for _ in range(tt):
	length = int(input())
	arr = list(map(int, input().split(' ')))
	result = 'YES' if main(arr) else 'NO'
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = True
	for i in range(n - 1):
		if a[i + 1] >= a[i]:
			k = False
			break
	if k:
		print('NO')
	else:
		print('YES')


def merge(array, trash, l, m, r):
	count = 0
	(i, j, k) = (l, m, l)
	while i <= m - 1 and j <= r:
		if array[i] <= array[j]:
			trash[k] = array[i]
			k += 1
			i += 1
		else:
			trash[k] = array[j]
			k += 1
			j += 1
			count = count + (m - i)
	while i <= m - 1:
		trash[k] = array[i]
		k += 1
		i += 1
	while j <= r:
		trash[k] = array[j]
		k += 1
		j += 1
	for i in range(l, r + 1, 1):
		array[i] = trash[i]
	return count

def lmao(array, trash, l, r):
	count = 0
	if r > l:
		m = int((r + l) / 2)
		count = lmao(array, trash, l, m)
		count += lmao(array, trash, m + 1, r)
		count += merge(array, trash, l, m + 1, r)
	return count

def Iswapit(array, n):
	trash = [0 for i in range(n)]
	return lmao(array, trash, 0, n - 1)
T = int(input())
while T != 0:
	n = int(input())
	array = [int(i) for i in input().split()]
	flag = 1
	n = len(array)
	if Iswapit(array, n) > n * (n - 1) / 2 - 1:
		flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')
	T -= 1


def swap(array, a, b):
	(array[a], array[b]) = (array[b], array[a])

def nsteps_sort(lista):
	array = lista.copy()
	n_elem = len(array)
	n_max = n_elem * (n_elem - 1) // 2 - 1
	count = 0
	for idx in range(n_elem):
		for other in range(idx, n_elem):
			if array[idx] > array[other]:
				swap(array, idx, other)
				count += 1
			if count > n_max:
				return 'NO'
	return 'YES'

def is_sorted(array):
	for elem in range(len(array) - 1):
		if array[elem] <= array[elem + 1]:
			return 'YES'
	return 'NO'
cases = int(input())
for i in range(cases):
	_ = input()
	cubes = list(map(int, input().split()))
	print(is_sorted(cubes))


t = int(input())

def merge_sort(arr):
	swaps = 0
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		swaps += merge_sort(L)
		swaps += merge_sort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] <= R[j]:
				arr[k] = L[i]
				i += 1
			else:
				swaps += len(L) - i
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
	return swaps
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	swaps = merge_sort(a)
	limit = n * (n - 1) // 2 - 1
	if swaps > limit:
		print('NO')
	else:
		print('YES')


import sys
import math, bisect
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

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

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	N = I()
	A = Neo()
	B = A[:]
	B.sort(reverse=True)
	if A == B and len(set(A)) == N:
		print('NO')
	else:
		print('YES')


t = int(input())
changer = 0
output = []
for i in range(t):
	n = int(input())
	inputString = input()
	a = [int(x) for x in inputString.split()]
	yes = True
	for x in range(1, n):
		if a[x] >= a[x - 1]:
			output.append('YES')
			yes = False
			break
		if x == n - 1 and yes == True:
			output.append('NO')
for i in range(t):
	print(output[i])


t = int(input())
for testCase in range(t):
	n = int(input())
	sorted = True
	a = [int(e) for e in input().split()]
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			sorted = False
			break
	if sorted:
		print('NO')
	else:
		print('YES')


num = int(input())
for i in range(num):
	n = int(input())
	lista = list(map(int, input().split()))
	no = True
	for j in range(n):
		if j > 0:
			if lista[j - 1] <= lista[j]:
				no = False
	if no:
		print('NO')
	else:
		print('YES')


import sys

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

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

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

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k 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
EPS = 10 ** (-10)

class BIT:

	def __init__(self, n):
		self.n = n
		n += 1
		nv = 1
		while nv < n:
			nv *= 2
		self.size = nv
		self.tree = [0] * nv

	def sum(self, i):
		s = 0
		i += 1
		while i > 0:
			s += self.tree[i - 1]
			i -= i & -i
		return s

	def add(self, i, x):
		i += 1
		while i <= self.size:
			self.tree[i - 1] += x
			i += i & -i

	def query(self, l, r):
		return self.sum(r - 1) - self.sum(l - 1)

	def get(self, i):
		return self.query(i, i + 1)

	def update(self, i, x):
		self.add(i, x - self.get(i))

	def print(self):
		for i in range(self.n):
			print(self.get(i), end=' ')
		print()

def compress(S):
	(zipped, unzipped) = ({}, {})
	for (i, a) in enumerate(sorted(S)):
		zipped[a] = i
		unzipped[i] = a
	return (zipped, unzipped)
for _ in range(INT()):
	N = INT()
	A = LIST()
	S = set(A + [0])
	(zipped, _) = compress(S)
	for i in range(N):
		A[i] = zipped[A[i]]
	bit = BIT(N + 1)
	ans = 0
	limit = N * (N - 1) // 2 - 1
	for i in range(N - 1, -1, -1):
		ans += bit.sum(A[i] - 1)
		bit.add(A[i], 1)
	if ans <= limit:
		YES()
	else:
		NO()


mod = 10 ** 9 + 7

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


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = set(a)
	k = list(a)
	k.sort(reverse=1)
	print('YES' if k != a or len(l) != n else 'NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	for i in range(1, n):
		if arr[i - 1] <= arr[i]:
			print('Yes')
			break
	else:
		print('NO')


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


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	j = 1
	f = 0
	while j < n:
		if b[j] < b[j - 1]:
			pass
		else:
			f = 1
			break
		j += 1
	if f == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == n and arr == sorted(arr, reverse=True):
		print('NO')
	else:
		print('YES')


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


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

def main():
	for t in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = 'NO'
		for i in range(1, n):
			if a[i] >= a[i - 1]:
				ans = 'YES'
				break
		print(ans)
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 math

def get_int():
	return int(input())

def get_ints():
	return [int(i) for i in input().split()]
for t in range(0, get_int()):
	n = get_int()
	cubes = get_ints()
	possible = False
	for i in range(1, n):
		if cubes[i - 1] <= cubes[i]:
			possible = True
			break
	if not possible:
		print('NO')
	else:
		print('YES')


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


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


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	ok = False
	for i in range(1, n):
		if ar[i - 1] <= ar[i]:
			ok = True
			break
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	ans = 'NO'
	n = int(input())
	c = [int(vol) for vol in input().split()]
	for i in range(len(c) - 1):
		if c[i] <= c[i + 1]:
			ans = 'YES'
	print(ans)


t = int(input())

class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (self.n + 1)

	def init(self, init_val):
		for (i, v) in enumerate(init_val):
			self.add(i, v)

	def add(self, i, x):
		i += 1
		while i <= self.n:
			self.bit[i] += x
			i += i & -i

	def sum(self, i, j):
		return self._sum(j) - self._sum(i)

	def _sum(self, i):
		res = 0
		while i > 0:
			res += self.bit[i]
			i -= i & -i
		return res

	def lower_bound(self, x):
		s = 0
		pos = 0
		depth = self.n.bit_length()
		v = 1 << depth
		for i in range(depth, -1, -1):
			k = pos + v
			if k <= self.n and s + self.bit[k] < x:
				s += self.bit[k]
				pos += v
			v >>= 1
		return pos
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = sorted(A)
	d = {}
	for (i, b) in enumerate(B):
		d[b] = i
	A = [d[a] for a in A]
	bit = BIT(max(A) + 1)
	ans = 0
	for a in A:
		ans += bit.sum(a + 1, bit.n)
		bit.add(a, 1)
	if ans <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


def solve(n, lst):
	(noDiff, noGreater) = (False, False)
	for i in range(n - 1):
		if lst[i] < lst[i + 1]:
			noGreater = True
		if lst[i] == lst[i + 1]:
			noDiff = True
	if not noDiff and (not noGreater):
		return 'NO'
	else:
		return 'YES'
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


import sys
from collections import defaultdict
name = sys.stdin.read()
jobGrid = []
isJob = True
row = []
grid = name.split('\n')
grid = grid[:-1]
number_of_cases = int(grid[0])
for i in range(number_of_cases):
	cases = list(map(int, grid[i * 2 + 2].split()))
	limit = int(len(cases) * (len(cases) - 1) / 2 - 1)
	worstcase = sorted(cases, reverse=True)
	ans = 'NO'
	for j in range(len(cases)):
		if cases[j] != worstcase[j]:
			ans = 'YES'
			break
	if len(set(cases)) != len(cases):
		ans = 'YES'
	print(ans)


def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count
t = int(input())
for abc in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	leng = len(l)
	if mergeSort(l, leng) > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


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


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	des = True
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			des = False
			break
	if des is True:
		print('NO')
	else:
		print('YES')
	T -= 1


from sys import stdin
import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

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

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

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

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for _ in range(inp()):
	n = inp()
	a = list(minp())
	temp = n * (n - 1) // 2 - 1
	if countSwaps(a, n) > temp:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(l)
	l1.sort(reverse=True)
	if l == l1 and len(set(l1)) == n:
		print('NO')
	else:
		print('YES')


fsa = int(input())
for asdt in range(fsa):
	n = int(input())
	x = 0
	p = input().split()
	for sdi in range(n):
		p[sdi] = int(p[sdi])
	o = list(p)
	q = list(set(p))
	if len(q) == len(p):
		x = 1
	o.sort(reverse=True)
	if p == o and x == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	b.sort(reverse=True)
	print('YES' if a != b or len(set(a)) < n else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print('NO' if len(set(a)) == len(a) and sorted(a) == list(reversed(a)) else 'YES')


def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = countSwaps(l, n)
	if ans <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	decreasing = True
	for j in range(1, n):
		if l[j] >= l[j - 1]:
			decreasing = False
			break
	print('NO' if decreasing else 'YES')


t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	f = 0
	for i in range(n - 1):
		if list1[i] > list1[i + 1]:
			f = 1
		else:
			f = 0
			break
	if f == 0:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
while t:
	(n, ans) = (int(input()), 1)
	a = list(map(int, input().split()))
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			ans += 1
	print('YES' if ans < n else 'NO')
	t -= 1


count = 0

def mergesort2(A):
	global count
	if len(A) > 1:
		n = len(A)
		m = int(n / 2)
		L = A[:m]
		R = A[m:n]
		mergesort2(L)
		mergesort2(R)
		i = 0
		j = 0
		k = 0
		n1 = m
		n2 = n - m
		while i < n1 and j < n2:
			if L[i] <= R[j]:
				A[k] = L[i]
				i += 1
				k += 1
			else:
				A[k] = R[j]
				j += 1
				k += 1
				count += n1 - i
		while i < n1:
			A[k] = L[i]
			i += 1
			k += 1
		while j < n2:
			A[k] = R[j]
			j += 1
			k += 1

def countInversions(arr):
	global count
	count = 0
	mergesort2(arr)
ans = []
for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	nax = n * (n - 1) // 2
	nax -= 1
	countInversions(A)
	if count <= nax:
		ans.append('YES')
	else:
		ans.append('NO')
for i in ans:
	print(i)


def solve():
	n = int(input())
	array = [int(i) for i in input().split()]
	can = False
	for i in range(1, n):
		if array[i] >= array[i - 1]:
			can = True
			break
	if can:
		return 'YES'
	else:
		return 'NO'
t = int(input())
while t:
	t -= 1
	print(solve())


from collections import Counter
cases = int(input())
for _ in range(cases):
	n = int(input())
	c = list(map(int, input().split()))
	r = list(Counter(c).most_common())
	if r[0][1] > 1:
		print('YES')
	elif c == sorted(c)[::-1]:
		print('NO')
	else:
		print('YES')


import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 998244353

def main():
	ans_ = ''
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		f = 0
		for i in range(1, n):
			if arr[i] >= arr[i - 1]:
				f = 1
				break
		ans_ += 'YNEOS'[f == 0::2] + '\n'
	print(ans_)
main()


def solve():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	flag = True
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			flag = False
			break
	if flag:
		print('NO')
	else:
		print('YES')
t = int(input().strip())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	flag = True
	for i in l:
		if i in d:
			flag = False
		else:
			d[i] = 1
	if flag:
		k = sorted(l, reverse=True)
		if k == l:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


def sol():
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == n and a == sorted(a, reverse=True):
		print('NO')
	else:
		print('YES')

def main():
	T = int(input())
	for t in range(T):
		sol()
main()


import collections
import math
n_tests = int(input())
answers = []

def sort_and_count(a, beg, end):
	if end <= beg:
		return 0
	mid = beg + (end - beg) // 2
	invs_l = sort_and_count(a, beg, mid)
	invs_r = sort_and_count(a, mid + 1, end)
	c = mid - beg + 1
	(i, j) = (beg, mid + 1)
	_a = []
	invs_cross = 0
	while i <= mid and j <= end:
		if a[i] <= a[j]:
			_a.append(a[i])
			c -= 1
			i += 1
		else:
			_a.append(a[j])
			invs_cross += c
			j += 1
	if i > mid:
		_a += a[j:end + 1]
	else:
		_a += a[i:mid + 1]
	assert len(_a) == end - beg + 1
	a[beg:end + 1] = _a
	return invs_cross + invs_l + invs_r
for t in range(n_tests):
	n_cubes = int(input())
	cubes = list(map(int, input().split()))
	limit = n_cubes * (n_cubes - 1) // 2
	invs = sort_and_count(cubes, 0, len(cubes) - 1)
	answer = 'YES' if invs < limit else 'NO'
	answers.append(answer)
for answer in answers:
	print(answer)


def minSwaps(arr):
	n = len(arr)
	ans = 0
	for i in range(n - 1):
		if arr[i + 1] >= arr[i]:
			ans = 1
			break
	return ans
t = int(input())
for o in range(t):
	n = int(input())
	l = str.split(input(), ' ')
	for i in range(n):
		l[i] = int(l[i])
	counter = minSwaps(l)
	if counter == 1:
		print('YES')
	else:
		print('NO')


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


def compute_exchange_num(n, cubes_vol_list):
	for i in range(len(cubes_vol_list)):
		if i + 1 != len(cubes_vol_list):
			if int(cubes_vol_list[i]) <= int(cubes_vol_list[i + 1]):
				return 'YES'
	return 'NO'
inputs_num = int(input())
inputs_cubes_num = []
inputs_list = []
while inputs_num > 0:
	cubes_num = int(input())
	cubes_vol = input().split(' ')
	inputs_cubes_num.append(cubes_num)
	inputs_list.append(cubes_vol)
	inputs_num -= 1
for i in range(len(inputs_list)):
	print(compute_exchange_num(inputs_cubes_num[i], inputs_list[i]))


t = int(input())
for u in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			b = True
	if b:
		print('YES')
	else:
		print('NO')


def main():
	_ = int(input())
	while _ > 0:
		_ -= 1
		n = int(input())
		a = list(map(int, input().split()))
		if n == 1:
			print('YES')
			continue
		flag = 0
		for i in range(0, len(a) - 1):
			if a[i] <= a[i + 1]:
				flag = 1
		if flag == 1:
			print('YES')
		else:
			print('NO')
main()


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


def checkIfDuplicates_1(listOfElems):
	if len(listOfElems) == len(set(listOfElems)):
		return True
	else:
		return False
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	l1 = []
	l = input().split()
	for i in l:
		l1.append(int(i))
	if checkIfDuplicates_1(l) == False:
		print('YES')
	else:
		l2 = l1.copy()
		l2.sort(reverse=True)
		f = 1
		for i in range(len(l1)):
			if l1[i] != l2[i]:
				f = 0
		if f == 1:
			print('NO')
		else:
			print('YES')


import sys
import os
from io import BytesIO, IOBase

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

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

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

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

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

def ddi():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
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 collections import defaultdict
from math import gcd, pi, inf
for _ in range(ii()):
	n = ii()
	a = li()
	f = 0
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			f = 1
			break
	if f:
		print('YES')
	else:
		print('NO')


t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	volumes = input().split()
	x = 0
	for i in range(n - 1):
		if int(volumes[i]) <= int(volumes[i + 1]):
			x += 1
	if x >= 1:
		answers.append('YES')
	else:
		answers.append('NO')
for j in range(len(answers)):
	print(answers[j])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a == sorted(a, reverse=True) and len(a) == len(set(a)):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	cubes = list(map(int, input().split()))
	result = 0
	loop_count = 0
	if n == 1:
		print('NO')
	else:
		for i in range(1, n):
			if cubes[i] >= cubes[i - 1]:
				print('YES')
				break
			elif i == n - 1:
				print('NO')


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


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	is_true = False
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			is_true = True
			break
	if is_true:
		print('YES')
	else:
		print('NO')


import math
t = int(input())
arr = []
nums = []
for i in range(t):
	nums.append(int(input()))
	arr.append(list(map(int, input().split(' '))))
for i in range(len(arr)):
	flag = 0
	if len(arr[i]) == 1:
		print('NO')
	else:
		for j in range(len(arr[i]) - 1):
			if arr[i][j] <= arr[i][j + 1]:
				flag = 1
				break
		if flag == 1:
			print('YES')
		else:
			print('NO')


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


tt = int(input())
while tt:
	tt -= 1
	n = int(input())
	l = list(map(int, input().split()))
	b = False
	for i in range(1, len(l)):
		if l[i] >= l[i - 1]:
			b = True
			break
	if b:
		print('YES')
	else:
		print('NO')


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = ['NO'] * T
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	for i in range(n - 1):
		if A[i] <= A[i + 1]:
			ans[t] = 'YES'
			break
print(*ans, sep='\n')


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()
	if len(set(arr)) != n:
		ans = 'YES'
	else:
		barr = arr.copy()
		barr.sort()
		barr.reverse()
		if barr == arr:
			ans = 'NO'
		else:
			ans = 'YES'
	answers.append(ans)
print(*answers, sep='\n')


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


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	r = len(set(a))
	if r == n and a == b[::-1]:
		stdout.write('NO' + '\n')
	else:
		stdout.write('YES' + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	setA = set(a)
	print('NO' if len(a) == len(setA) and a == sorted(a)[::-1] else 'YES')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = 0
	for j in range(len(a) - 1):
		if a[j] <= a[j + 1]:
			b += 1
			print('YES')
			break
	if b == 0:
		print('NO')


def bubble_sort(n, a):
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
	b = sorted(list(d.keys()), reverse=True)
	if b == a:
		return 'NO'
	else:
		return 'YES'
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(bubble_sort(n, l))


def cube(arr):
	if len(arr) == 1:
		return (arr, 0)
	(a, ai) = cube(arr[:len(arr) // 2])
	(b, bi) = cube(arr[len(arr) // 2:])
	inversion = ai + bi
	c = []
	k = j = 0
	while k < len(a) and j < len(b):
		if a[k] > b[j]:
			inversion += len(a) - k
			c.append(b[j])
			j += 1
		else:
			c.append(a[k])
			k += 1
	c += a[k:]
	c += b[j:]
	return (c, inversion)
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(arr, x) = cube(l)
	a = n * (n - 1) // 2 - 1
	if x <= a:
		print('YES')
	else:
		print('NO')


def iinput():
	return [int(i) for i in input().split()]
t = int(input())
for _ in range(t):
	n = int(input())
	mas = iinput()
	mas1 = sorted(mas, reverse=True)
	if mas == mas1 and len(set(mas)) == len(mas):
		print('NO')
	else:
		print('YES  ')


for _ in range(int(input())):
	n = int(input())
	form = n * (n - 1) // 2 - 1
	arr = list(map(int, input().split()))
	count = 'NO'
	for i in range(1, n):
		if arr[i - 1] <= arr[i]:
			count = 'YES'
	print(count)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	if sorted(ar) == ar or len(set(ar)) != n:
		print('YES')
	elif sorted(ar, reverse=True) == ar:
		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
	for i in range(1, n):
		if arr[i] < arr[i - 1]:
			continue
		else:
			flag = False
			break
	if flag:
		print('NO')
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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 binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
for xyz in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	r = sorted(l)
	r = r[::-1]
	t = set(l)
	if r == l and len(t) == n:
		print('NO')
	else:
		print('YES')


from math import *
from random import *
from bisect import *
from math import *
for t in range(int(input())):
	n = int(input())
	mas = list(map(int, input().split()))
	f = False
	for i in range(1, n):
		if mas[i] >= mas[i - 1]:
			f = True
			break
	if f:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout

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

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

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

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

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

def gls():
	return list(stdin.readline().strip())

def gi():
	return int(stdin.readline())
t = gi()
while t:
	t -= 1
	n = gi()
	ar = gari()
	sr = sorted(ar, reverse=True)
	if ar == sr and len(set(ar)) == n:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	f = 'NO'
	n = int(input())
	li = list(map(int, input().split()))
	for i in range(1, n):
		if li[i] >= li[i - 1]:
			f = 'YES'
			break
	print(f)


import math

def fun(arr, n):
	if arr == sorted(arr, reverse=True) and len(set(arr)) == n:
		print('NO')
		return
	print('YES')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	fun(arr, n)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	s = set(a)
	if len(a) != len(s):
		print('YES')
		continue
	tt = sorted(a)
	if tt[::-1] != a:
		print('YES')
	else:
		print('NO')


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


def merge(A, aux, low, mid, high):
	k = i = low
	j = mid + 1
	inversionCount = 0
	while i <= mid and j <= high:
		if A[i] <= A[j]:
			aux[k] = A[i]
			i = i + 1
		else:
			aux[k] = A[j]
			j = j + 1
			inversionCount += mid - i + 1
		k = k + 1
	while i <= mid:
		aux[k] = A[i]
		k = k + 1
		i = i + 1
	for i in range(low, high + 1):
		A[i] = aux[i]
	return inversionCount

def mergeSort(A, aux, low, high):
	if high == low:
		return 0
	mid = low + (high - low >> 1)
	inversionCount = 0
	inversionCount += mergeSort(A, aux, low, mid)
	inversionCount += mergeSort(A, aux, mid + 1, high)
	inversionCount += merge(A, aux, low, mid, high)
	return inversionCount
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	A = arr.copy()
	c = mergeSort(arr, A, 0, n - 1)
	if c <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


def isDescending(arr):
	flag = True
	for i in range(n - 2, -1, -1):
		if arr[i] <= arr[i + 1]:
			flag = False
			break
	return flag
for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	if not isDescending(arr):
		print('YES')
	else:
		print('NO')


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


from typing import List

def cubesSorting(N: int, cubes: List[int]) -> str:
	for i in range(len(cubes) - 1):
		if cubes[i] <= cubes[i + 1]:
			return 'YES'
	return 'NO'
test_cases = int(input())
for _ in range(test_cases):
	N = int(input())
	inputs = list(map(int, input().split(' ')))
	print(cubesSorting(N, inputs))


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	n = II()
	a = LI()
	sa = sorted(a, reverse=True)
	num = len(set(a))
	if num == n and sa == a:
		print('NO')
	else:
		print('YES')


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


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	data = idata()
	d = sorted(data)[::-1]
	flag = 1
	for i in range(1, n):
		if d[i] == d[i - 1]:
			flag = 0
	if data == d and flag:
		print('NO')
	else:
		print('YES')
	return
for t in range(int(ii())):
	solve()


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


t = int(input())

def q(l, n):
	for i in range(n - 1):
		if l[i] <= l[i + 1]:
			return 'YES'
	return 'NO'
for i in range(t):
	n = int(input())
	i = input().split()
	l = list(map(int, i))
	print(q(l, n))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().rsplit()))
	(inc, di, ii) = (False, 0, 0)
	if n > 1:
		for i in range(n - 1):
			if a[i] <= a[i + 1]:
				inc = True
				break
	if inc == True or n == 1:
		print('Yes')
	else:
		print('No')


T = int(input())
for i in range(T):
	N = int(input())
	lst = list(map(int, input().split()))
	x = []
	flag = 0
	count = 1
	for i in range(len(lst) - 1):
		if lst[i + 1] == lst[i]:
			count += 1
	if count == len(lst):
		print('YES')
	else:
		for i in range(1, len(lst)):
			if lst[i] >= lst[i - 1]:
				flag = 1
				break
		if flag == 1:
			print('YES')
		else:
			print('NO')


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


def solve(arr):
	for i in range(len(arr) - 1):
		if arr[i] <= arr[i + 1]:
			print('YES')
			return
	print('NO')
t = int(input())
for i in range(t):
	input()
	arr = tuple(map(int, input().split()))
	solve(arr)


t = int(input())
for test_cases in range(t):
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	pro = 1
	i = 1
	while i < n:
		if l[i - 1] <= l[i]:
			pro = pro * 0
		i += 1
	if pro == 0:
		print('YES')
	else:
		print('NO')


import sys
from collections import defaultdict
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if len(lis) > len(set(lis)):
		print('YES')
		continue
	res = lis[:]
	res.sort()
	if res == lis:
		print('YES')
		continue
	lis.reverse()
	if lis == res:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	de = True
	for a in range(n - 1):
		de = de and arr[a] > arr[a + 1]
	if de:
		print('NO')
	else:
		print('YES')


def rs(A):
	for i in range(len(A) - 1):
		if not A[i] > A[i + 1]:
			return False
	return True

def ans(A):
	if rs(A):
		return 'NO'
	return 'YES'
T = int(input())
for t in range(T):
	input()
	A = list(map(int, input().split()))
	print(ans(A))


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = sorted(l1.copy(), reverse=True)
	if len(set(l1)) == n and l1 == l2:
		print('NO')
	else:
		print('YES')


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


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = a.copy()
	c = a.copy()
	c.sort()
	f = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			f = 1
			break
	if f == 1:
		print('YES')
	else:
		a.sort()
		a = a[::-1]
		if b == a:
			print('NO')
		else:
			print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	x = sorted(arr)
	x = x[::-1]
	if arr == x and len(arr) == len(set(arr)):
		print('NO')
	else:
		print('YES')


n = int(input())
for i in range(n):
	(a, ai) = (input(), list(map(int, input().split())))
	b = sorted(ai, reverse=True)
	if ai != b or len(b) > len(set(b)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	mi = ar[0]
	flag = False
	for i in range(1, n):
		if ar[i] >= mi:
			flag = True
			break
		else:
			mi = ar[i]
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
ans = list(('NO' for i in range(t)))
for j in range(t):
	n = int(input())
	mxex = n * (n - 1) / 2
	a = list(map(int, input().split()))
	i = 0
	while i != n - 1:
		if a[i] <= a[i + 1]:
			ans[j] = 'YES'
			break
		i += 1
for i in range(t):
	print(ans[i])


def process():
	n = int(input())
	li = list(map(int, input().split()))
	m = list(li)
	if len(set(m)) < len(m):
		return 'YES'
	m.sort(reverse=True)
	for i in range(0, n):
		if li[i] != m[i]:
			return 'YES'
	return 'NO'
tests = int(input())
for i in range(tests):
	print(process())


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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 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 = 10 ** 9 + 7

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 zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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(case):
	n = int(inp())
	a = lis()
	if a == sorted(a):
		print('YES')
		return
	if n == len(set(a)) and a == sorted(a)[::-1]:
		print('NO')
	else:
		print('YES')
testcase(int(inp()))


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	t = l
	if len(set(l)) == n and sorted(l) == l[::-1]:
		print('NO')
	else:
		print('YES')


for case in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	pointer = 'NO'
	for i in range(1, n):
		if lst[i - 1] <= lst[i]:
			pointer = 'YES'
			break
	print(pointer)


import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(sys.stdin.readline())
	input = sys.stdin.readline()
	ar = list(map(int, input.split()))
	flag = 0
	for i in range(1, n):
		if ar[i - 1] == ar[i]:
			flag = 1
	flag1 = 0
	for i in range(1, n):
		if ar[i - 1] < ar[i]:
			flag1 = 1
	if flag == 1:
		print('YES')
	elif flag1 == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = int(input())
	l = list(map(int, input().split()))
	b = sorted(l)[::-1]
	if l == b and len(set(b)) == a:
		print('NO')
	else:
		print('YES')


from collections import *
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(a)
	b.sort(reverse=True)
	if a != b:
		print('YES')
	elif a[0] == a[-1]:
		print('YES')
	elif len(set(b)) != len(b):
		print('YES')
	else:
		print('NO')


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


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


import os
from io import BytesIO, IOBase
import sys

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(sorted(a, reverse=True))
		f = False
		for i in range(n - 1):
			if b[i] == b[i + 1]:
				f = True
		if f:
			print('YES')
		else:
			print('NO' if a == b else 'YES')
	return
BUFSIZE = 1048576

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))

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


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	b.reverse()
	tag = 1
	cnt = 0
	last = 0
	for i in range(n):
		if last != a[i]:
			cnt += 1
			last = a[i]
		if a[i] != b[i]:
			tag = 0
			break
	if tag and cnt == n:
		print('NO')
	else:
		print('YES')


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


t = int(input())
ans = []
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	can = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			can = True
			break
	if can:
		ans.append('YES')
	else:
		ans.append('NO')
	t -= 1
for i in ans:
	print(i)


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

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()
	decre = False
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			decre = True
	if decre:
		print('YES')
	else:
		print('NO')


import sys
from bisect import *
from collections import deque
pl = 1
from copy import *
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

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

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	if len(set(a)) == 1 or len(set(a)) != len(a):
		print('YES')
		continue
	print('YES' if a != sorted(a, reverse=True) else 'NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	result = 'Null'
	for i in range(1, n):
		if a[i - 1] > a[i]:
			result = 'No'
		else:
			result = 'Yes'
			break
	print(result)


def getint():
	return int(input())

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

def getlistints():
	return list(map(int, input().split()))
for _ in range(getint()):
	n = getint()
	nums = getlistints()
	flag = False
	for i in range(n - 1):
		if nums[i] <= nums[i + 1]:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ar1 = ar
	ar1 = sorted(ar1)
	prev = ar1[0]
	found = 0
	for i in range(1, n):
		if ar1[i] == prev:
			found = 1
			break
		else:
			prev = ar1[i]
	if ar == sorted(ar, reverse=True) and found != 1:
		print('NO')
	else:
		print('YES')


def readGenerator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def solve(n, a):
	f = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			f = True
			break
	return 'YES' if f else 'NO'
t = readInt()
for _ in range(0, t):
	n = readInt()
	a = [readInt() for _ in range(0, n)]
	print(solve(n, a))


T = int(input())
array = []
for t in range(0, T):
	n = int(input())
	array = [int(s) for s in input().split()]
	count = 0
	done = 0
	for i in range(0, len(array)):
		if i <= len(array) - 2:
			if array[i] <= array[i + 1]:
				done = 1
				break
	if done == 1:
		print('YES')
	else:
		print('NO')


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


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	if sorted(l) == l[::-1] and len(list(set(l))) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().split()
	c = []
	for j in a:
		c.append(int(j))
	a = c
	bl = True
	for k in range(0, len(a) - 1):
		if a[k] > a[k + 1]:
			continue
		else:
			bl = False
			break
	if not bl:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	ip = [int(x) for x in input().split()]
	flag = 0
	for j in range(0, n - 1):
		if ip[j] <= ip[j + 1]:
			print('YES')
			flag = 1
			break
	if flag == 0:
		print('NO')


t = int(input())
for tc in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	ans = 0
	flag = True
	for i in range(1, n):
		if li[i - 1] <= li[i]:
			flag = False
	if not flag:
		print('YES')
	else:
		print('NO')


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

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

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

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		br = list(set(ar))
		if len(br) == n:
			ok = False
			for i in range(len(ar) - 1):
				if ar[i] < ar[i + 1]:
					ok = True
					break
			if not ok:
				print('NO')
			else:
				print('YES')
		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()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	flag = True
	for j in range(1, n):
		if not a[j] < a[j - 1]:
			flag = False
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	prev = 1000000001
	k = 0
	a = input().split(' ')
	for j in range(n):
		if prev > int(a[j]):
			k += 1
		prev = int(a[j])
	if k == n:
		print('NO')
	else:
		print('YES')


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


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
import io
import os
input = sys.stdin.readline
import random
mo = 10 ** 9 + 7

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

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

def sin():
	return input()

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

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for _ in range(inin()):
	n = inin()
	arr = ain()
	s = countSwaps(arr, n)
	if s > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


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


T = int(input())
res = list()
for i in range(T):
	n = int(input())
	x = list(map(int, input().split()))
	ans = False
	for j in range(len(x) - 1):
		if x[j] <= x[j + 1]:
			ans = True
			break
		else:
			ans = False
	if ans:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	solved = False
	for j in range(1, n):
		if a[j] >= a[j - 1]:
			print('YES')
			solved = True
			break
	if not solved:
		print('NO')


for _ in range(int(input())):
	input()
	data = list(map(int, input().split()))
	reversed = True
	for index in range(1, len(data)):
		if data[index] >= data[index - 1]:
			reversed = False
			break
	print(('YES', 'NO')[reversed])


import sys
import math
mod = 10 ** 9 + 7
inf = float('inf')
from collections import defaultdict

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

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

class BinaryIndexedTree:

	def __init__(self, size):
		self.bit = [0 for _ in range(size)]
		self.size = size

	def add(self, i, w):
		x = i + 1
		while x <= self.size:
			self.bit[x - 1] += w
			x += x & -x
		return

	def sum(self, i):
		res = 0
		x = i + 1
		while x > 0:
			res += self.bit[x - 1]
			x -= x & -x
		return res
t = I()
for _ in range(t):
	n = I()
	a = LI()
	b = sorted(a)
	d = defaultdict(int)
	for i in range(n):
		d[b[i]] = i
	BIT = BinaryIndexedTree(n + 1)
	cnt = 0
	for (i, ai) in enumerate(a):
		BIT.add(d[ai], 1)
		cnt += i + 1 - BIT.sum(d[ai])
	if cnt > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


import time, math as mt, bisect as bs, sys
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 IP():
	return map(int, stdin.readline().split())

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

def P(x):
	return stdout.write(str(x) + '\n')

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 bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(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(2 * 10 ** 5 + 5):
		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 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def get_ans(arr, s, e, k):
	t = list(arr[s:e + 1])
	t.sort(reverse=True)
	dont = 0
	for i in range(len(t)):
		(cnt, br) = (t[i][0], t[i][1])
		if br <= k:
			k -= br
			dont += cnt
	return dont

def solve():
	n = II()
	li = L()
	t = list(li)
	t.sort(reverse=True)
	x = [li[0] for i in range(n)]
	if t == li and x != li:
		d = {}
		for ele in li:
			d[ele] = d.get(ele, 0) + 1
		for ele in d:
			if d[ele] > 1:
				print('YES')
				return
		print('NO')
		return
	else:
		print('YES')
	return
t = II()
for i in range(t):
	solve()


def funct(arr, n):
	c = 0
	for i in range(len(arr) - 1):
		if arr[i] <= arr[i + 1]:
			return 'YES'
	return 'NO'
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	print(funct(arr, n))


def main(a):
	flag = True
	for i in range(len(a) - 1):
		if a[i] <= a[i + 1]:
			flag = False
	return flag
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if main(a):
		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()
	b = list(sorted(a))
	mp = {}
	for i in range(n):
		d = mp.get(a[i], 0)
		mp[a[i]] = d + 1
	if b[::-1] == a and max(mp.values()) == 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')
for i in range(scanner()):
	solve()


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	if sorted(a) == a:
		print('YES')
	elif sorted(a, reverse=True) == a and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	yes = 'NO'
	for i in range(1, len(arr)):
		if arr[i] >= arr[i - 1]:
			yes = 'YES'
			break
	print(yes)


import sys
import os
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')
mod = 10 ** 9 + 7

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

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, lst):
	lst1 = sorted(lst, reverse=True)
	if len(set(lst)) == n and lst1 == lst:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


for i in range(int(input())):
	l = int(input())
	p = [int(x) for x in input().split()]
	a = 0
	for j in range(1, len(p)):
		if p[j] >= p[j - 1]:
			a = a + 1
	if a > 0:
		print('YES')
	else:
		print('NO')


def get(l, t, s, m, e):
	c = 0
	i = s
	j = m
	k = s
	while i <= m - 1 and j <= e:
		if l[i] <= l[j]:
			t[k] = l[i]
			k += 1
			i += 1
		else:
			t[k] = l[j]
			k += 1
			j += 1
			c += m - i
	while i <= m - 1:
		t[k] = l[i]
		k += 1
		i += 1
	while j <= e:
		t[k] = l[j]
		k += 1
		j += 1
	for i in range(s, e + 1, 1):
		l[i] = t[i]
	return c

def ms(l, t, s, e):
	c = 0
	if e > s:
		m = s + (e - s) // 2
		c = ms(l, t, s, m)
		c += ms(l, t, m + 1, e)
		c += get(l, t, s, m + 1, e)
	return c

def ans(l, n):
	t = [0 for i in range(n)]
	return ms(l, t, 0, n - 1)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = ans(l, n)
	if x <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	f = 0
	z = sorted(l)
	if n >= 2 and len(list(set(l))) == n:
		f = 1
	if l == z[::-1] and f == 1:
		print('NO')
	else:
		print('YES')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ok = 'NO'
	for x in range(1, n):
		if arr[x - 1] <= arr[x]:
			ok = 'YES'
			break
	print(ok)


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


t = int(input())
for _ in range(t):
	n = int(input())
	l = list([int(x) for x in input().split()])
	e = len(set(l))
	nl = sorted(l)
	nl.reverse()
	if n != e:
		print('YES')
	elif l == nl:
		print('NO')
	else:
		print('YES')


import sys
import heapq
import copy
import math
import decimal
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 insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

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

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

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

def pri(a, b):
	s = '? ' + str(a) + ' ' + str(b)
	print(s)
	sys.stdout.flush()

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	hashm = {}
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		n = inp()
		a = inlt()
		flag = 0
		for i in range(1, n):
			if a[i] >= a[i - 1]:
				flag = 1
				break
		if flag == 1:
			print('YES')
		else:
			print('NO')
main()


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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == n:
		b = sorted(a, reverse=True)
		f = False
		for j in range(len(b)):
			if b[j] != a[j]:
				print('YES')
				f = True
				break
		if f == False:
			print('NO')
	else:
		print('YES')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:]
	b.sort()
	b = b[::-1]
	c = set(a)
	if a == b:
		if len(c) == len(a):
			print('NO')
		else:
			print('YES')
	else:
		print('YES')
	return

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

def __starting_point():
	main()
__starting_point()


t = int(input())
for q in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = sorted(arr, reverse=True)
	if arr == brr and len(arr) == len(set(arr)):
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)

def solve(n):
	l = list(map(int, input().split()))
	c = countSwaps(l, n)
	m = n * (n - 1) // 2 - 1
	if m >= c:
		return 'YES'
	else:
		return 'NO'
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


for _ in range(int(input())):
	n = int(input())
	cnt = False
	ls = [int(x) for x in input().split()]
	for i in range(n - 1):
		if ls[i] <= ls[i + 1]:
			cnt = True
			break
	if cnt:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	t_count = n * (n - 1) / 2 - 1
	flag = False
	for i in range(len(lis) - 1):
		if lis[i] > lis[i + 1]:
			continue
		else:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

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 inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') 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()
	good = True
	b = sorted(a)
	for i in range(1, n):
		if b[i] == b[i - 1]:
			good = False
			break
	for i in range(n):
		if b[n - i - 1] != a[i]:
			good = False
			break
	if good:
		print('NO')
	else:
		print('YES')


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


T = int(input())
for I in range(0, T):
	N = int(input())
	X = list(map(int, input().split()))
	A = 0
	Bool = 'NO'
	while A < len(X) - 1:
		if X[A] <= X[A + 1]:
			Bool = 'YES'
		A += 1
	print(Bool)


import sys
input = sys.stdin.readline
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = ip()
	flag = 1
	for i in range(n - 1):
		if x[i] > x[i + 1]:
			flag = 0
		else:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))[:n]
	s_d = 1
	for i in range(n - 1):
		if a[i] - a[i + 1] > 0:
			s_d = 1
		else:
			s_d = 0
			break
	if s_d == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


def solve(n, a):
	sorte = True
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			sorte = False
			break
	return 'NO' if sorte else 'YES'
t = int(input())
while t:
	res = []
	n = int(input())
	in_ = map(int, input().split(' '))
	for x in in_:
		res.append(int(x))
	print(solve(n, res))
	t -= 1


t = int(input())
while t:
	ans = False
	n = int(input())
	a = [int(i) for i in input().split()]
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			ans = True
			break
	if ans:
		print('YES')
	else:
		print('NO')
	t -= 1


import os, sys
from io import BytesIO, IOBase

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

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

def instr():
	s = input()
	return list(s[:len(s)])

def inmap():
	return map(int, input().split())
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
for i in range(inp()):
	n = inp()
	a = inlist()
	flag = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			continue
		flag = 1
		break
	print('YES') if flag == 1 else print('NO')


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) < n:
		print('YES')
		continue
	narr = sorted(arr, reverse=True)
	flag = False
	for i in range(n):
		if arr[i] != narr[i]:
			print('YES')
			flag = True
			break
	if not flag:
		print('NO')


def merge(n, a, temp_arr, l, mid, r):
	icount = 0
	i = l
	j = mid + 1
	k = l
	while i <= mid and j <= r:
		if a[i] <= a[j]:
			temp_arr[k] = a[i]
			i += 1
			k += 1
		else:
			icount += mid - i + 1
			temp_arr[k] = a[j]
			j += 1
			k += 1
	while i <= mid:
		temp_arr[k] = a[i]
		k += 1
		i += 1
	while j <= r:
		temp_arr[k] = a[j]
		k += 1
		j += 1
	for i in range(l, r + 1):
		a[i] = temp_arr[i]
	return icount

def merge_sort(n, a, temp_arr, l, r):
	if l >= r:
		return 0
	inv_count = 0
	mid = (r + l) // 2
	inv_count += merge_sort(n, a, temp_arr, l, mid)
	inv_count += merge_sort(n, a, temp_arr, mid + 1, r)
	inv_count += merge(n, a, temp_arr, l, mid, r)
	return inv_count

def ans(n, a):
	limit = n * (n - 1) // 2
	temp_arr = [0 for i in range(n)]
	count = merge_sort(n, a, temp_arr, 0, n - 1)
	return count < limit
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split(' ')))
	print('YES' if ans(n, a) else 'NO')
	t -= 1


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
import math
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()
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(max(n - r, 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 main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		res = 'NO'
		for i in range(1, n):
			if a[i] >= a[i - 1]:
				res = 'YES'
		print(res)
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()


import sys
input = sys.stdin.readline

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


import bisect

def main(lst):
	if len(lst) == 1:
		return True
	new_lst = [lst[0]]
	op = 0
	for i in range(1, len(lst)):
		index = bisect.bisect_right(new_lst, lst[i])
		op += len(new_lst) - index
		new_lst.insert(index, lst[i])
	if op <= len(lst) * (len(lst) - 1) // 2 - 1:
		return True
	return False
a = int(input())
for i in range(a):
	b = input()
	lst = list(map(int, input().split()))
	if main(lst):
		print('YES')
	else:
		print('NO')


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
GAP = 2
for t in [wtf[i:i + GAP] for i in range(1, len(wtf), GAP)]:
	n = int(t[0])
	A = list(map(int, t[1].split()))
	f = False
	for i in range(1, n):
		if A[i - 1] <= A[i]:
			f = True
			break
	print('NO' if not f else 'YES')


for s in [*open(0)][2::2]:
	a = [*map(int, s.split())]
	print('NYOE S'[len(set(a)) < len(a) or a != sorted(a)[::-1]::2])


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


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	if A == sorted(A):
		print('YES')
		continue
	B = sorted(A, reverse=True)
	for (a, b) in zip(A, B):
		if a != b:
			print('YES')
			break
	else:
		if len(set(B)) == n:
			print('NO')
		else:
			print('YES')


def solve(n, l):
	g = l[0]
	count = 1
	for i in range(1, n):
		if l[i] < g:
			count += 1
		g = l[i]
	if count == n:
		return False
	return True
t = int(input())
for we in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if solve(n, l):
		print('YES')
	else:
		print('NO')


import sys
import math
from collections import Counter
from collections import OrderedDict

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)

def myXOR(x, y):
	return (x | y) & (~x | ~y)
t = int(inputt())
for _ in range(t):
	n = int(inputt())
	l = listt()
	count = 1
	for i in range(n - 1):
		if l[i] > l[i + 1]:
			count += 1
	if count == n:
		print('NO')
	else:
		print('Yes')


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


def duplicate(l):
	s = set()
	for i in l:
		if i in s:
			return True
		else:
			s.add(i)
	return False

def aaks(L, n):
	for i in range(1, n):
		if L[i] > L[i - 1]:
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	l = input()
	L = l.split()
	for i in range(n):
		L[i] = int(L[i])
	if aaks(L, n) and (not duplicate(L)):
		print('NO')
	else:
		print('YES')


import sys, os, io
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for tc in range(1, 1 + int(I())):
	n = int(I())
	a = list(map(int, I().split()))
	f = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			f = True
			break
	print('YES' if f else 'NO')


for x in range(int(input())):
	a = int(input())
	m = 1
	l = list(map(int, input().split()))
	b = list(sorted(l, reverse=True))
	if len(set(l)) == 1:
		print('YES')
	elif l == b and len(set(b)) == len(l):
		print('NO')
	else:
		print('YES')


try:
	T = int(input())
	for _ in range(T):
		result = True
		n = int(input())
		values = list(map(int, input().split()))
		for i in range(n - 1):
			check = values[i] > values[i + 1]
			result &= check
		if not result:
			print('YES')
		else:
			print('NO')
except Exception:
	pass


for p in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	i = 0
	c = 'NO'
	while i < n - 1:
		if ls[i] <= ls[i + 1]:
			c = 'YES'
			break
		i += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = False
	for i in range(1, n):
		if a[i - 1] > a[i]:
			pass
		else:
			res = True
			break
	if res:
		print('Yes')
	else:
		print('No')


def answer(n, ary):
	for i in range(len(ary) - 1):
		if ary[i] <= ary[i + 1]:
			return 'YES'
	return 'NO'

def main():
	t = int(input())
	n = [0] * t
	ary = [0] * t
	for j in range(t):
		n[j] = int(input())
		ary[j] = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(n[j], ary[j]))
main()


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	can = False
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')
	t = t - 1


import sys
from collections import defaultdict as dc
import math
from bisect import bisect, bisect_left, bisect_right
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = set(l)
	x = sorted(l, reverse=True)
	if len(p) < n:
		print('YES')
	elif l == x:
		print('NO')
	else:
		print('YES')


from collections import Counter
from collections import OrderedDict
from collections import defaultdict

def SOCountR(mylist):
	return OrderedDict(sorted(Counter(mylist).items(), reverse=True))

def SOCount(mylist):
	return OrderedDict(sorted(Counter(mylist).items()))

def freq_count(mylist):
	return Counter(mylist)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr1 = arr.copy()
	arr1.sort(reverse=True)
	set1 = set(arr)
	if arr == arr1 and len(arr) == len(set1):
		print('NO')
	else:
		print('YES')


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	repeat = {}
	repeated = False
	for ai in a:
		if ai not in repeat:
			repeat[ai] = 1
		else:
			repeated = True
	if b == a and repeated is False:
		print('NO')
	else:
		print('YES')


class BinaryIndexedTree:

	def __init__(self, n):
		self.n = n
		self.BIT = [0] * (self.n + 1)

	def add(self, i, x):
		while i <= self.n:
			self.BIT[i] += x
			i += i & -i

	def query(self, i):
		res = 0
		while i > 0:
			res += self.BIT[i]
			i -= i & -i
		return res

def zaatu(a):
	l = sorted(set(a))
	d = {l[i]: i for i in range(len(l))}
	return [d[i] for i in a]
t = int(input())
for _ in range(t):
	n = int(input())
	BIT = BinaryIndexedTree(n)
	a = list(map(int, input().split()))
	a = zaatu(a)
	cnt = 0
	for i in range(n):
		cnt += i - BIT.query(a[i] + 1)
		BIT.add(a[i] + 1, 1)
	print('YES' if cnt <= n * (n - 1) // 2 - 1 else 'NO')


import os
import sys
from io import BytesIO, IOBase

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

def main2():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = 0
		cnt = [0] * 100
		for i in range(n):
			c = len(bin(a[i])[2:])
			ans += cnt[c]
			cnt[c] += 1
		print(ans)

def main3():
	for _ in range(int(input())):
		(n, q) = map(int, input().split())
		a = list(map(int, input().split()))
		flag = 1
		ans = 0
		for i in range(1, n - 1):
			if flag:
				if a[i - 1] < a[i] > a[i + 1]:
					ans += a[i]
					flag = 0
			if not flag:
				if a[i - 1] > a[i] < a[i + 1]:
					ans -= a[i]
					flag = 1
		if flag:
			if a[n - 1] > a[n - 2]:
				ans += a[n - 1]
		print(ans)
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')
main1()


t = int(input())
for j in range(t):
	n = int(input())
	nlist = list(map(int, input().split()))[:n]
	f = 0
	v = 10 ** 10
	for i in range(n):
		if nlist[i] < v:
			v = nlist[i]
		else:
			f = 1
	if f == 1:
		print('YES')
	else:
		print('NO')


query = int(input())
for i in range(query):
	size = int(input())
	arr = list(map(int, input().split()))
	possible = size * (size - 1) // 2 - 1
	f = 0
	count = 0
	possible = False
	for j in range(size - 1):
		if arr[j + 1] >= arr[j]:
			possible = True
			break
	if possible:
		print('Yes')
	else:
		print('NO')


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = a[:]
	s.sort(reverse=True)
	dic = defaultdict(lambda : 0)
	temp = 0
	for i in a:
		if dic[i] == 0:
			dic[i] += 1
		else:
			temp = 1
			break
	if temp == 1:
		print('YES')
	elif a == s:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = l[:]
	m.sort()
	m = m[-1::-1]
	if m == l and len(set(l)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for q in range(0, t):
	n = int(input())
	s = input()
	lst = list(map(int, s.split()))
	case = (n * n - n) // 2 - 1
	flag = 1
	for i in range(1, n):
		if lst[i] >= lst[i - 1]:
			flag = 0
	if flag == 0:
		print('YES')
	else:
		print('NO')


def m(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += m(arr, temp, left, mid + 1, right)
	return inv_count

def cc(arr):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, len(arr) - 1)
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	if cc(s) > n * (n - 1) / 2 - 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	moves = n * (n - 1) // 2
	moves -= 1
	ans = 0
	for i in range(0, len(a) - 1):
		if a[i] > a[i + 1]:
			ans += 1
	ans = ans * (ans + 1) // 2
	if ans > moves:
		print('NO')
	else:
		print('YES')


import math

def solve(arr):
	bool = False
	for i in range(1, len(arr)):
		if arr[i] >= arr[i - 1]:
			bool = True
			break
	if bool:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(arr)


for _ in range(int(input())):
	n = int(input())
	threashold = n * (n - 1) // 2 - 1
	l = list(map(int, input().split()))
	count = 0
	i = 0
	while i < n - 1:
		if l[i] > l[i + 1]:
			t = 0
			j = i
			while j < n - 1 and l[j] > l[j + 1]:
				t += 1
				j += 1
			count += t * (t + 1) // 2
			i = j
		else:
			i += 1
	print('NO' if count > threashold else 'YES')


from sys import stdin, stdout
ans = []

def main():
	n = int(stdin.readline())
	volu = list(map(int, stdin.readline().split()))
	count = 1
	for i in range(n - 1):
		if volu[i] > volu[i + 1]:
			continue
		count = 0
		break
	if count:
		ans.append('NO')
	else:
		ans.append('YES')
for _ in range(int(stdin.readline())):
	main()
stdout.write('\n'.join(ans))


import math

def solve(n, arr):
	for i in range(n - 1):
		if arr[i] <= arr[i + 1]:
			return 'YES'
	return 'NO'
	pass
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans.append(solve(n, arr))
for test in ans:
	print(test)


def ans(a, n):
	if a == sorted(a):
		return 'YES'
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			return 'YES'
	z = [i for i in a]
	z.sort(reverse=True)
	if z == a:
		return 'NO'
	return 'YES'
m = int(input())
for i in range(m):
	n = int(input())
	arr = input().split()
	a = []
	for i in arr:
		a.append(int(i))
	print(ans(a, n))


import sys
import math

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 len(set(a)) == n and a == sorted(a)[::-1]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	inp = list(map(int, input().split()))
	ninp = sorted(inp)[::-1]
	if ninp == inp and len(set(inp)) == n:
		print('NO')
	else:
		print('YES')


for run in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	srt = lst.copy()
	srt.sort(reverse=True)
	if srt == lst and len(set(srt)) == n:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	numbers = list(map(int, input().split()))
	current = numbers[0]
	can = False
	for i in range(1, n):
		if numbers[i] < current:
			current = numbers[i]
		else:
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	cubes = int(input())
	weights = list(map(int, input().split(' ')))
	descend = True
	for j in range(1, len(weights)):
		if weights[j] >= weights[j - 1]:
			descend = False
			break
	if descend == False:
		print('YES')
	else:
		print('NO')


t = int(input())
for r in range(t):
	n = int(input())
	max_n = int(n * (n - 1) / 2) - 1
	same = False
	possible = False
	a = list(map(int, input().split()))
	for i in range(n - 2, -1, -1):
		if a[i + 1] >= a[i]:
			possible = True
			break
	if possible:
		print('YES')
	else:
		print('NO')


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = int(input())
while t:
	t -= 1
	n = inp()
	a = lis()
	fl = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			fl += 1
			continue
	if fl == n - 1:
		print('NO')
	else:
		print('YES')


import sys, math, time
start_time = time.time()

def read():
	return int(input())

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

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

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

def hocus_pocus():
	n = read()
	a = read_array()
	if len(a) == len(set(a)) and a == sorted(a, reverse=True):
		print('NO')
	else:
		print('YES')
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
else:
	sys.stdin = open('D:\\pro_code\\py\\in.txt', 'r')
	sys.stdout = open('D:\\pro_code\\py\\out.txt', 'w')
global tc
tt = 1
tt = read()
for tc in range(1, tt + 1):
	hocus_pocus()
if not ONLINE_JUDGE:
	print('Time elapsed :', time.time() - start_time, 'secs')
	sys.stdout.close()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	lst = list(map(int, sys.stdin.readline().split()))
	set_len = len(set(lst))
	if set_len == 1:
		print('YES')
		continue
	if set_len == n:
		if lst == sorted(lst, reverse=True):
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	if len(set(a)) == len(a) and a == b:
		print('NO')
	else:
		print('YES')


from collections import Counter
t = int(input())
while t > 0:
	n = int(input())
	l = [int(x) for x in input().split()]
	s = False
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			s = True
			break
	if s:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	check = list(arr)
	check2 = list(arr)
	check.sort(reverse=True)
	if len(set(arr)) == n:
		if check == arr:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = a.copy()
	l.sort()
	l.reverse()
	if l == a and len(set(a)) == len(a):
		print('NO')
	else:
		print('YES')


for test in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split(' ')))
	limit = int(n * (n - 1) / 2 - 1)
	count = 0
	flag = 0
	for i in range(1, len(l)):
		if l[i] >= l[i - 1]:
			print('YES')
			flag = 1
			break
	if flag == 0:
		print('NO')


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


for o in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	a = s.copy()
	a.sort(reverse=True)
	p = 'NO'
	r = {}
	for i in s:
		try:
			r[i] = r[i] + 1
			p = 'YES'
			break
		except:
			r[i] = 0
	if p == 'NO':
		for i in range(n):
			if a[i] != s[i]:
				p = 'YES'
				break
	print(p)


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


from sys import stdout, stdin
(_input, _print) = (stdin.readline, stdout.write)
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = [_int(i) for i in _input().split()]
		for i in _range(n - 1):
			if arr[i] <= arr[i + 1]:
				print('YES')
				break
		else:
			print('NO')
solution()


def merge_sort(A):
	if len(A) <= 1:
		return (0, A)
	middle = len(A) // 2
	(left_inversions, left) = merge_sort(A[:middle])
	(right_inversions, right) = merge_sort(A[middle:])
	(merge_inversions, merged) = merge(left, right)
	inversions = left_inversions + right_inversions + merge_inversions
	return (inversions, merged)

def merge(left, right):
	result = []
	(i, j, inversions) = (0, 0, 0)
	while i < len(left) and j < len(right):
		if left[i] <= right[j]:
			inversions += j
			result.append(left[i])
			i += 1
		else:
			result.append(right[j])
			j += 1
	inversions += j * (len(left) - i)
	result += left[i:]
	result += right[j:]
	return (inversions, result)
t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	(ans, a) = merge_sort(a)
	if ans > n * (n - 1) / 2 - 1:
		print('NO')
	else:
		print('YES')
	t -= 1


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()
	b = sorted(a)[::-1]
	if sorted(a) == sorted(set(a)) and a == b:
		print('NO')
	else:
		print('YES')


def readGenerator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def solve(a):
	return 'YES' if any(filter(lambda v: v[0] <= v[1], zip(a, a[1:]))) else 'NO'
t = readInt()
for _ in range(0, t):
	n = readInt()
	a = [readInt() for _ in range(0, n)]
	print(solve(a))


for _ in range(int(input())):
	k = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) < k:
		print('YES')
	else:
		b = a.copy()
		b.sort(reverse=True)
		if b == a and b[0] != b[k - 1]:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	size = int(input())
	nums = list(map(int, input().split(' ')))
	new = sorted(nums, reverse=True)
	if nums == new and len(new) == len(set(new)):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	status = False
	for j in range(1, n):
		if a[j] >= a[j - 1]:
			status = True
			break
	if status:
		print('YES')
	else:
		print('NO')


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


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == n and a == sorted(a)[::-1]:
		print('NO')
	else:
		print('YES')


def maxx(x):
	return x * (x - 1) / 2 - 1
n = int(input())
for _ in range(n):
	lixo = input()
	l = list(map(int, input().split()))
	tam = len(l)
	sim = 0
	for i in range(tam - 1):
		if l[i] <= l[i + 1]:
			sim = 1
	if sim:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	D = dict()
	for _ in range(n):
		if A[_] in D:
			print('YES')
			break
		else:
			D[A[_]] = 1
	else:
		if A == sorted(A, reverse=True):
			print('NO')
		else:
			print('YES')


from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.read().splitlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx]
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

def problem_solver():

	def solver(inpt):
		(n,) = inpt.array()
		a = inpt.array()
		ok = False
		for i in range(1, n):
			if a[i - 1] <= a[i]:
				ok = True
		print('YES' if ok else 'NO')
	return solver
try:
	solver = problem_solver()
	for tc in Input().known_tests():
		solver(tc)
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


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()
	f = 0
	for i in range(n - 1):
		if arr[i + 1] >= arr[i]:
			f = 1
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


x = int(input())
ans = []
q = ''
for i in range(x):
	c = int(input())
	a = list(map(int, input().split()))
	m = c * (c - 1) // 2 - 1
	for j in range(c - 1):
		if a[j] <= a[j + 1]:
			q = 'YES'
			break
		else:
			q = 'NO'
	ans.append(q)
for row in ans:
	print(row)


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	op = 0
	flag = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			flag = True
	if flag:
		print('YES')
	else:
		print('NO')


class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (n + 1)
		self.el = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.bit[i]
			i -= i & -i
		return s

	def add(self, i, x):
		self.el[i] += x
		while i <= self.n:
			self.bit[i] += x
			i += i & -i

	def get(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i - 1)

	def lower_bound(self, x):
		w = i = 0
		k = 1 << self.n.bit_length()
		while k:
			if i + k <= self.n and w + self.bit[i + k] < x:
				w += self.bit[i + k]
				i += k
			k >>= 1
		return i + 1
import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = ['YES'] * T
comp = lambda arr: {e: i + 1 for (i, e) in enumerate(sorted(set(arr)))}
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	compA = comp(A)
	bit = BIT(N)
	cnt = 0
	for i in range(N):
		cnt += i - bit.sum(compA[A[i]])
		bit.add(compA[A[i]], 1)
	if cnt >= N * (N - 1) // 2:
		ans[t] = 'NO'
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	p = int(a == sorted(a, reverse=True) and len(set(a)) == n)
	print(['YES', 'NO'][p])


for cases in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	condition = (n * n - n - 2) // 2
	value = True
	for i in range(n - 1):
		if lst[i] > lst[i + 1]:
			pass
		else:
			value = False
			break
	if value:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	id = 0
	a = list(map(int, input().split()))
	for i in range(0, len(a) - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			id = 1
			break
	if id == 0:
		print('NO')


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


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	flag = 0
	for x in range(n - 1):
		if b[x] == b[x + 1]:
			flag = 1
	if flag == 0 and a == b:
		print('NO')
	else:
		print('YES')
	t -= 1


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 print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	a = RLL()
	flag = True
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			print('YES')
			flag = False
			break
	if flag:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	num = list(reversed(sorted(l)))
	if l == list(sorted(l)) or len(set(l)) < len(l):
		print('YES')
	elif l == num:
		print('NO')
	else:
		print('YES')


def main():
	t = int(input())
	for case in range(t):
		n = int(input())
		ar = [int(x) for x in input().split()]
		arr = [0] * n
		for i in reversed(range(n - 1)):
			if ar[i] > ar[i + 1]:
				arr[i] = arr[i + 1] + 1
			else:
				arr[i] = arr[i + 1]
		if sum(arr) > n * (n - 1) / 2 - 1:
			print('NO')
		else:
			print('YES')
main()


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


t = int(input())
for i in range(t):
	n = int(input())
	cubes = list(map(int, input().split()))
	result = 'NO'
	for i in range(1, n):
		if cubes[i] >= cubes[i - 1]:
			result = 'YES'
	print(result)


tests = int(input())
data = []
for i in range(tests):
	n = int(input())
	x = list(map(int, input().split()))
	data.append(x)
for set in data:
	N = len(set)
	check = N * (N - 1) / 2 - 1
	swaps = 0
	for i in range(N - 1):
		if set[i] <= set[i + 1]:
			print('YES')
			break
		if i == N - 2:
			print('NO')


from sys import stdin
input = stdin.readline
from math import ceil

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


from collections import Counter
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	ans = True
	for i in c.values():
		if i >= 2:
			ans = False
			break
	if not ans:
		print('YES')
	elif a == sorted(a)[::-1]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	reversed_and_sorted_a = list(reversed(sorted(a)))
	dictionary = {}
	flag = 0
	for num in a:
		if num not in dictionary:
			dictionary[num] = 1
		else:
			flag = 1
			break
	if flag == 1:
		print('YES')
	else:
		reversed_and_sorted_a = list(reversed(sorted(a)))
		print('YES' if reversed_and_sorted_a != a or sorted(a) == a else '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()]
	for i in range(N - 1):
		if A[i] <= A[i + 1]:
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans = False
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			ans = True
			print('YES')
			break
	if not ans:
		print('NO')


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 ceil(x, y=1):
	return int(-(-x // y))
import math
from collections import defaultdict
for _ in range(ri()):
	n = ri()
	l = ria()
	a = l.copy()
	a.sort(reverse=True)
	cnt = 0
	if len(set(l)) < n:
		ws('YES')
	elif l == a:
		ws('NO')
	else:
		ws('YES')


import math

def main():
	t = int(input())
	for _ in range(t):
		print(case())

def case():
	n = int(input())
	a = list(map(int, input().split()))
	if a == sorted(a, reverse=True) and len(set(a)) == n:
		return 'NO'
	return 'YES'
main()


def main():
	T = int(input())
	while T > 0:
		T -= 1
		N = int(input())
		v = list(map(int, input().split()))
		valid = False
		for i in range(1, N):
			if v[i] >= v[i - 1]:
				valid = True
		print('YES' if valid else 'NO')
main()


import sys
import bisect
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	n = ini()
	a = inl()
	if len(set(a)) == n and a == sorted(a, reverse=True):
		print('NO')
	else:
		print('YES')


def merge(lst1, lst, l, m, right):
	countRev = 0
	(i, j, k) = (l, m, l)
	while i <= m - 1 and j <= right:
		if lst1[i] <= lst1[j]:
			lst[k] = lst1[i]
			k += 1
			i += 1
		else:
			lst[k] = lst1[j]
			k += 1
			j += 1
			countRev = countRev + (m - i)
	while i <= m - 1:
		lst[k] = lst1[i]
		k += 1
		i += 1
	while j <= right:
		lst[k] = lst1[j]
		k += 1
		j += 1
	for i in range(l, right + 1, 1):
		lst1[i] = lst[i]
	return countRev

def sorting(lst1, lst, l, right):
	countRev = 0
	if right > l:
		m = int((right + l) / 2)
		countRev = sorting(lst1, lst, l, m)
		countRev += sorting(lst1, lst, m + 1, right)
		countRev += merge(lst1, lst, l, m + 1, right)
	return countRev

def swapNum(lst1, n):
	lst = [0 for i in range(n)]
	return sorting(lst1, lst, 0, n - 1)
for i in range(int(input())):
	n = int(input())
	lst3 = list(map(int, input().split()))
	if n * (n - 1) // 2 - 1 < swapNum(lst3, n):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()][:n]
	s = set(l)
	if len(s) == n:
		m = l.copy()
		m.sort(reverse=True)
		if m == l:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for _ in range(0, int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	s = sorted(v, reverse=True)
	d = v == s
	c = n - len(set(v))
	print(['YES', 'NO'][d and c == 0])


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	isReverse = True
	for i in range(n - 1):
		isReverse = isReverse and a[i] > a[i + 1]
	if isReverse:
		print('NO')
	else:
		print('YES')


def check(ar):
	i = 0
	n = len(ar)
	while i < n - 1 and ar[i + 1] < ar[i]:
		i += 1
	return i == n - 1 and len(set(ar)) == n
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	if check(ls):
		print('NO')
	else:
		print('YES')


import sys

def main():
	T = int(input())
	for ti in range(T):
		n = int(input())
		A = [int(a) for a in input().split()]
		ans = 'NO' if n > 1 else 'YES'
		for i in range(len(A) - 1):
			if A[i] <= A[i + 1]:
				ans = 'YES'
		print(ans)
main()


from sys import maxsize as inf
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().rstrip().split()))
TEST_CASES = True

def main():
	n = get_int()
	a = get_list()
	flag = 0
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			flag = 1
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = a.copy()
	b.sort(reverse=True)
	k = 0
	for j in range(n - 1):
		if b[j] == b[j + 1]:
			k = 1
			print('YES')
			break
	if k == 1:
		continue
	if b == a:
		print('NO')
		continue
	else:
		print('YES')
		continue


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('YES') if x else print('NO')
for _ in range(rn()):
	n = rn()
	l = rl()
	ans = False
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			ans = True
			break
	yn(ans)


import math
for z in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	temp = a.copy()
	temp.sort(reverse=True)
	if len(set(a)) == n and temp == a:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	l = r.copy()
	r.sort(reverse=True)
	print('NO' if ''.join(map(str, l)) == ''.join(map(str, r)) and len(l) == len(set(l)) else 'YES')


def solve(n):
	s = list(map(int, input().split()))
	k = s[0]
	for i in range(1, n):
		if k <= s[i]:
			return 'YES'
		k = min(k, s[i])
	return 'NO'
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr_copy = list(sorted(arr, reverse=True))
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			print('YES')
			return
	if arr_copy == arr:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	main()


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	for j in range(n):
		print('NO' if l[::-1] == sorted(l) and len(l) == len(set(l)) else 'YES')
		break


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


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

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

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 gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		arr = li()
		d = defaultdict(int)
		dub = False
		for i in arr:
			d[i] += 1
			if d[i] > 1:
				dub = True
		tmp = sorted(arr, reverse=True)
		if arr == tmp and (not dub):
			ans += 'NO\n'
		else:
			ans += 'YES\n'
	print(ans)
main()


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

def get_int_input():
	return list(map(int, get_input()))

def main():
	T = get_int_input()[0]
	for _ in range(T):
		n = get_int_input()[0]
		nums = get_int_input()
		flag = 0
		for i in range(n - 1):
			if nums[i] <= nums[i + 1]:
				print('YES')
				flag = 1
				break
		if not flag:
			print('NO')
main()


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	arr = []
	temparr = temparr.split()
	for i in temparr:
		arr.append(int(i))
	sortedarr = sorted(arr)
	revarr = sortedarr[::-1]
	uniq = {}
	for i in revarr:
		if i not in uniq:
			uniq[i] = 1
		else:
			uniq[i] += 1
	if len(uniq) < n:
		print('YES')
	else:
		diff = False
		for i in range(n):
			if revarr[i] != arr[i]:
				diff = True
				break
		if diff:
			print('YES')
		else:
			print('NO')


import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
import itertools
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = inpl()
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for a in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = True
	for x in range(1, n):
		if arr[x] < arr[x - 1]:
			continue
		else:
			flag = False
			break
	if not flag:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	array = list(map(int, stdin.readline().split()))
	flag = True
	for i in range(1, n):
		if array[i] >= array[i - 1]:
			flag = False
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = 'NO'
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			ans = 'Yes'
			break
	print(ans)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	n = int(input())
	f = 1
	a = list(map(int, sys.stdin.readline().split(' ')))
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			continue
		else:
			f = 0
	if f == 0:
		print('YES')
	else:
		print('NO')
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


k = int(input())
for i in range(k):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			print('YES')
			break
	else:
		if a == b and b[0] != b[n - 1]:
			print('NO')
		else:
			print('YES')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = 0
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			print('YES')
			f = 1
			break
	if f == 0:
		print('NO')


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	if len(s) != n:
		print('YES')
	elif sorted(a, reverse=True) != a:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	flag = False
	arr = [int(x) for x in input().split()]
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			print('YES')
			flag = True
			break
	if not flag:
		print('NO')


def check(n, ar):
	for i in range(1, n):
		if ar[i] >= ar[i - 1]:
			return True
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().rstrip().split()))
	if check(n, ar):
		print('YES')
	else:
		print('NO')


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


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = set(a)
	k = len(l)
	if k < n:
		print('YES')
		continue
	r = a.copy()
	r.sort(reverse=True)
	for i in range(n):
		if a[i] != r[i]:
			print('YES')
			break
	else:
		print('NO')


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	n = IN()
	a = LI()
	f = 0
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			f = 1
			break
	if f:
		print('YES')
	else:
		print('NO')
for _ in range(IN()):
	case()


for test in range(int(input())):
	pocet = int(input())
	a = list(map(int, input().split(' ')))
	ok = False
	for i in range(pocet - 1):
		if a[i] <= a[i + 1]:
			ok = True
	if ok:
		print('YES')
	else:
		print('NO')


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


for i in range(int(input())):
	n = int(input())
	ar = [int(i) for i in input().split()]
	if len(set(ar)) == n and ar == sorted(ar, reverse=True):
		print('NO')
	else:
		print('YES')


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = 0
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			c = a[i]
			a[i] = a[i + 1]
			a[i + 1] = c
			d += 1
	if d != 0:
		print('Yes')
	else:
		print('No')


from collections import deque
from math import ceil
import sys
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = []
	for i in a:
		b.append(i)
	b.sort(reverse=True)
	if a != b or len(set(a)) < n:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):

	def yesno(n, arr):
		for i in range(1, n):
			if arr[i - 1] <= arr[i]:
				return 'YES'
				break
		return 'NO'
	N = int(input())
	ar = list(map(int, input().split()))
	print(yesno(N, ar))


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


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


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = sorted(A)
	B.reverse()
	if A != B or len(set(A)) < n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(reversed(list(sorted(l))))
	if l == m and len(set(l)) == n:
		print('NO')
	else:
		print('YES')


def cube(test):
	n = int(input())
	count = 0
	lst = list(map(int, input().split()))
	for i in range(len(lst) - 1):
		if lst[i] > lst[i + 1]:
			count += 1
	if count == len(lst) - 1:
		return 'NO'
	else:
		return 'YES'
t = int(input())
l = []
for i in range(t):
	res = cube(i)
	l.append(res)
for i in l:
	print(i)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	pp = False
	jj = 0
	count = 0
	for i in range(1, n):
		if ar[i] < ar[i - 1]:
			count += 1
			pp = True
		jj += 1
	if count == n - 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	b = sorted(ar, reverse=True)
	fl = 0
	prv = b[0]
	for i in range(1, n):
		if prv == b[i]:
			fl = 1
			break
		prv = b[i]
	if fl == 1:
		print('YES')
		continue
	for i in range(n):
		if ar[i] != b[i]:
			fl = 1
			break
	if ar.count(ar[0]) == n:
		fl = 1
	if fl == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	revsort = arr.copy()
	revsort.sort()
	revsort.reverse()
	print('NO') if len(set(arr)) == N and arr == revsort else print('YES')


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(mi())
	ans = 0
	b = sorted(a, reverse=True)
	for i in range(n):
		if a[i] != b[i]:
			ans = 1
	if len(set(a)) < n:
		ans = 1
	if ans:
		print('YES')
	else:
		print('NO')


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


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


def main():
	t = int(input())
	while t > 0:
		n = int(input())
		li = list(map(int, input().split()))
		found = 0
		for i in range(n - 1):
			if li[i] > li[i + 1]:
				continue
			else:
				found = 1
				break
		if found == 1:
			print('YES')
		else:
			print('NO')
		t -= 1
main()


n = int(input())
for i in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	s = set(b)
	x = []
	x.extend(b)
	x.sort(reverse=True)
	if len(b) == len(s) and x == b:
		print('NO')
	else:
		print('YES')


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


from sys import stdin
A = int(stdin.readline())
for t in range(0, A):
	B = int(stdin.readline())
	C = list(map(int, stdin.readline().split()))
	for k in range(1, B):
		if C[k] >= C[k - 1]:
			print('YES')
			break
		if k == B - 1:
			print('NO')
			break


t = int(input())
for _ in range(t):
	int(input())
	a = list(map(int, input().split()))
	swap = False
	for i in range(1, len(a)):
		if a[i - 1] <= a[i]:
			swap = True
			break
	if swap:
		print('YES')
	else:
		print('NO')


def solve(lst):
	p = sorted(lst)
	same = 0
	for i in range(len(lst) - 1):
		if p[i] == p[i + 1]:
			same += 1
	if p == lst[::-1] and p[0] != p[len(lst) - 1] and (same == 0):
		return 'NO'
	return 'YES'
k = int(input())
for i in range(k):
	p = int(input())
	lst = list(map(int, input().split()))
	print(solve(lst))

class FPTree:

	def __init__(self, item=None):
		self.node = FPNode(1, item or None)

	def getNode(self):
		return self.node

	def add(self, transaction):
		temprory_mem = self.node
		for item in transaction:
			new_searched = temprory_mem.search(item)
			if new_searched:
				new_searched.increment()
			else:
				new_searched = FPNode(1, item)
				temprory_mem.add(new_searched)
			temprory_mem = new_searched

class FPNode:

	def __init__(self, count, item):
		self.children = {}
		self.item = item
		self.count = count
		self.parent = None

	def getItem(self):
		return self.item

	def getChildren(self):
		return self.children

	def add(self, child):
		if child not in self.children:
			child.parent = self
			self.children[child.item] = child
			return True
		return False

	def search(self, item):
		try:
			return self.children[item]
		except KeyError:
			return None

	def increment(self):
		self.count += 1


for _ in ' ' * int(input()):
	input()
	a = [int(x) for x in input().split()]
	for (a, b) in zip(a, a[1:]):
		if a <= b:
			a = 0
			break
	print('NYOE S'[a == 0::2])


n = int(input())
for _ in range(n):
	k = int(input())
	m = list(map(int, input().split()))
	answer = 'NO'
	for i in range(k - 1):
		if m[i] <= m[i + 1]:
			answer = 'YES'
			break
	print(answer)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	lis2 = lis[:]
	lis.sort(reverse=True)
	if lis == lis2:
		se = set(lis)
		if len(se) == len(lis):
			print('NO')
			continue
	print('YES')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [i for i in a]
	b.sort()
	if a == b:
		print('YES')
	elif a == sorted(a, reverse=True) and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	n = len(arr)
	K = N * (N - 1) / 2 - 1
	c = countSwaps(arr, n)
	if c > K:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	array = [int(i) for i in input().split()]
	can = False
	for i in range(1, len(array)):
		if array[i] >= array[i - 1]:
			can = True
			break
	print('YES') if can else print('NO')


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	min = a[0]
	ans = 'No'
	for i in range(1, n):
		if a[i] >= min:
			ans = 'Yes'
			break
		else:
			min = a[i]
	print(ans)


t = int(input())
for _ in range(t):
	int(input())
	a = list(map(int, input().split()))
	if a == list(reversed(sorted(a))) and len(set(a)) == len(a):
		print('NO')
	else:
		print('YES')


import sys

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()
	l = list(reversed(sorted(a)))
	s = list(set(a))
	if a == l and len(s) == n:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	another = arr.copy()
	another.sort(reverse=True)
	if arr != another or len(set(arr)) < n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	b = []
	for i in arr:
		b.append(i)
	b.sort()
	if b == arr:
		print('YES')
	else:
		a = []
		for i in arr:
			a.append(i)
		a.sort(reverse=True)
		if n == 2:
			print('NO')
		elif arr == a and len(set(arr)) == n:
			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 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

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

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
getcontext().prec = 8
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793
import random

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = sorted(a)
		b = b[::-1]
		if n == len(set(a)) and a == b:
			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())
	data = [int(x) for x in input().split()]
	if len(set(data)) < n:
		print('YES')
	else:
		temp = sorted(data, reverse=True)
		if data == temp:
			print('NO')
		else:
			print('YES')


T = int(input())
for t in range(T):
	N = int(input())
	L = list(map(int, input().split()))
	L1 = L[:]
	L2 = L[:]
	L1.sort(reverse=True)
	L2.sort()
	var = len(set(L)) == N
	if L == L1 and L != L2 and var:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a == sorted(a):
		print('Yes')
		continue
	if a == sorted(a, reverse=True) and len(list(set(a))) == n:
		print('No')
	else:
		print('Yes')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = 10000000000000000000000
	t = False
	for j in range(n):
		if f <= l[j]:
			t = True
		f = l[j]
	print('YES' if t else 'NO')


def sum(bit, index):
	s = 0
	while index > 0:
		s += bit[index]
		index -= index & -index
	return s

def update(bit, index, n, val):
	while index <= n:
		bit[index] += val
		index += index & -index
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	na = a.copy()
	a.sort()
	b = dict()
	cur = 1
	for i in range(n):
		if a[i] in b:
			continue
		b[a[i]] = cur
		cur += 1
	for i in range(n):
		na[i] = b[na[i]]
	bit = [0] * (n + 1)
	count = 0
	lim = n * (n - 1) // 2
	for i in na[::-1]:
		count += sum(bit, i - 1)
		update(bit, i, n, 1)
	print('YES' if count < lim else 'NO')


from collections import Counter, defaultdict as dft

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

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

def solve():
	n = int(input())
	arr = ml()
	temp = sorted(arr)
	if arr == temp:
		print('YES')
		return
	if len(set(arr)) == n and arr == temp[::-1]:
		print('NO')
		return
	print('YES')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	a.reverse()
	b = len(set(a))
	if a == sorted(a) and b == n:
		print('NO')
	else:
		print('YES')


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)

def gs(fr=None):
	return map_type_to_fr(str, fr)[0]
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1\n'.split('\n')

def solve():
	n = i2i()
	a = mis()
	viewed = set(a)
	if len(viewed) != n:
		return 'YES'
	s = sorted(a, reverse=True)
	if a == s:
		return 'NO'
	return 'YES'
q = i2i()
for i in range(q):
	print(solve())


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


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


q = int(input())
for _ in range(q):
	length = int(input())
	alist = [int(i) for i in input().split()]
	res = 'NO'
	for i in range(length - 1):
		if alist[i] <= alist[i + 1]:
			res = 'YES'
			break
	print(res)


def main():
	n = int(input())
	lst = list(map(int, input().split()))
	istrue = 1
	allsame = 1
	seta = set()
	for i in range(n):
		seta.add(lst[i])
	for i in range(1, n):
		if lst[i] > lst[i - 1]:
			istrue = 0
			break
	for i in range(1, n):
		if lst[i] != lst[i - 1]:
			allsame = 0
			break
	if allsame == 1:
		print('YES')
	elif istrue == 1:
		if len(seta) < n:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
t = int(input())
while t != 0:
	main()
	t -= 1


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	b = sorted(a, reverse=True)
	if a == b and len(s) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 1
	while i < n:
		if a[i] >= a[i - 1]:
			print('YES')
			break
		i += 1
	if i == n:
		print('NO')


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	brr = copy.deepcopy(arr)
	brr.sort(reverse=True)
	isPossible = False
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			isPossible = True
			break
	if isPossible:
		print('YES')
	else:
		print('NO')


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


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	sortedA = list(sorted(a, reverse=True))
	if a == sortedA and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	n = int(input())
	nums = list(map(int, input().split()))
	possible = False
	for i in range(1, n, 1):
		if nums[i - 1] <= nums[i]:
			possible = True
			break
	if possible:
		print('YES')
	else:
		print('NO')
	t -= 1


T = int(input())
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 'NO'
	for i in range(n - 1):
		if A[i] <= A[i + 1]:
			ans = 'YES'
			break
	print(ans)


a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	n = c.copy()
	n.reverse()
	m = list(set(c))
	if len(n) == len(m):
		c.sort()
		p = 0
		for y in range(len(c)):
			if c[y] == n[y]:
				p += 1
			else:
				print('YES')
				break
		if p == len(c):
			print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	y = True
	for k in range(0, n - 1):
		if l1[k] > l1[k + 1]:
			continue
		else:
			y = False
			break
	if y:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
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
for _ in range(I()):
	n = I()
	(*a,) = R()
	if len(set(a)) != n or sorted(a)[::-1] != a:
		print('YES')
	else:
		print('NO')


def check(a, n):
	z = sorted(a, reverse=True)
	if z[::-1] == a:
		return 'YES'
	if z == a and len(set(a)) == n:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(check(a, n))


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


tests = int(input())
for _ in range(tests):
	no = int(input())
	arr = list(map(int, input().split()))
	my_set = set(arr)
	rev_list = sorted(arr, reverse=1)
	if no == len(my_set) and arr == rev_list:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(set(a))
	if len(b) < n:
		print('YES')
	else:
		a1 = sorted(a, reverse=True)
		if a == a1:
			print('NO')
		else:
			print('YES')


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

def si():
	return input()

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

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

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

def out(v):
	print(v)

def spout():
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

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

def ispow2(x):
	return x and (not x & x - 1)

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 list(factors)
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	f = 0
	for i in range(n - 1):
		if a[i + 1] >= a[i]:
			f = 1
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import os
import 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 main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		flag = 1
		for i in range(0, n - 1):
			if a[i] <= a[i + 1]:
				print('YES')
				flag = 0
				break
		if flag == 1:
			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()


import sys
input = sys.stdin.readline
import copy
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	S = set(a)
	check = copy.copy(a)
	check.sort()
	check.reverse()
	if len(S) == n and check == a:
		print('NO')
	else:
		print('YES')


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


from math import *
from collections import deque
from copy import deepcopy
import sys

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

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

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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
t = int(input())
for _ in range(t):
	n = int(inp())
	a = lis()
	flag = False
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			print('YES')
			flag = True
			break
	if not flag:
		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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			ans += 1
	req = n * (n - 1) // 2 - 1
	print('YES' if ans else 'NO')


testcases = int(input())
while testcases:
	size = int(input())
	counter = 0
	array = list(map(int, input().split()))
	for i in range(len(array) - 1):
		if array[i] > array[i + 1]:
			counter += 1
	if counter >= size - 1:
		print('NO')
	else:
		print('YES')
	testcases -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [-int(i) for i in input().split(' ')]
	if a == sorted(a) and min([abs(a[i] - a[i + 1]) for i in range(n - 1)]) > 0:
		print('NO')
	else:
		print('YES')


s = int(input())
for _ in range(s):
	status = False
	t = int(input())
	n = list(map(int, input().split()))
	for i in range(t - 1):
		if n[i] <= n[i + 1]:
			status = True
			break
	if status:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			ans = 1
			break
	ans = 'NO' if ans is 0 else 'YES'
	print(ans)


for s in [*open(0)][2::2]:
	a = list(map(int, s.split()))
	print('YNEOS'[len(set(a)) == len(a) and a == sorted(a)[::-1]::2])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():

	def solve():
		n = int(input())
		numbers = [int(x) for x in input().split()]
		for i in range(1, n):
			if numbers[i] >= numbers[i - 1]:
				print('YES')
				return
		print('NO')
	t = int(input())
	for i in range(t):
		solve()
BUFFSIZE = 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, BUFFSIZE))
			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, BUFFSIZE))
			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')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	a = inlt()
	if len(a) == len(set(a)) and a == sorted(a, reverse=True):
		print('NO')
	else:
		print('YES')

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(1, t + 1):
		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):
	q = [0] * max(a)
	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 factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	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):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def ceil(a, b):
	return -(-a // b)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import sys
t = int(input())
for tc in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	lst_set = set(lst)
	if len(lst_set) == len(lst) and lst == sorted(lst, reverse=True):
		print('No')
	else:
		print('yes')


T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	flags = []
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			flags.append(False)
		else:
			flags.append(True)
	if sum(flags):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	cond = False
	for i in range(1, n):
		if lst[i] >= lst[i - 1]:
			cond = True
	if cond:
		print('YES')
	else:
		print('NO')


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


import sys

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count
t = int(input())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	ans = n * (n - 1) / 2 - 1
	count = mergeSort(arr, n)
	if count > ans:
		print('NO')
	else:
		print('YES')


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

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

def liinput():
	return [int(_) for _ in input().split()]

def lfinput():
	return [float(_) for _ in input().split()]
T = iinput()
for _ in range(T):
	n = iinput()
	a = liinput()
	if len(set(a)) < len(a):
		print('YES')
		continue
	b = sorted(a, reverse=True)
	flag = False
	for (i, j) in zip(a, b):
		if i != j:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


m = int(input())
for _ in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	yes = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			yes = True
			break
	if yes:
		print('YES')
	else:
		print('NO')


import sys
import math
mod = 998244353
inf = float('inf')
from collections import defaultdict

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

def LI():
	return list(map(int, sys.stdin.readline().split()))
t = I()
for _ in range(t):
	n = I()
	a = LI()
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			continue
		break
	else:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	d = set(w)
	if len(w) == len(d) and w == sorted(w)[::-1]:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	z = []
	for i in range(n - 1):
		if l[i] > l[i + 1]:
			z.append(l[i])
		else:
			print('YES')
			break
	else:
		print('NO')


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

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

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 inp():
	return sys.stdin.readline()

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

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

def is_descending(arr):
	for i in range(len(arr) - 1):
		if arr[i] < arr[i + 1]:
			return False
	return True

def solve():
	n = itg()
	arr = tuple(mpint())
	return not (len(set(arr)) == n and is_descending(arr))
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
for _ in range(itg()):
	print('YES' if solve() else 'NO')


import sys

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
for i in range(int(input())):
	n = int(input())
	li = get_list()
	se = set(li)
	if len(se) == n and sorted(li, reverse=True) == li:
		print('NO')
	else:
		print('YES')


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


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	can = False
	for i in range(1, n):
		if ls[i] >= ls[i - 1]:
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')


N = int(input())
for _ in range(N):
	n = int(input())
	nums = list(map(int, input().split()))
	stack = []
	flag = 0
	for i in range(n - 1):
		if nums[i] <= nums[i + 1]:
			flag |= 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	flag = False
	for i in range(len(ar) - 1):
		if ar[i] <= ar[i + 1]:
			flag = True
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	x = int(input())
	(*li,) = map(int, input().split())
	for i in range(1, x):
		if li[i] >= li[i - 1]:
			print('YES')
			break
	else:
		print('NO')


_ = int(input())
while _:
	_ -= 1
	n = int(input())
	nums = list(map(int, input().split()))
	cnt = 0

	def merge(left, right):
		global cnt
		if right - left > 1:
			mid = (left + right) // 2
			t1 = merge(left, mid)
			t2 = merge(mid + 1, right)
			temp = []
			p = 0
			q = 0
			while p < len(t1) or q < len(t2):
				if q >= len(t2) or (p < len(t1) and t1[p] <= t2[q]):
					temp.append(t1[p])
					p += 1
				else:
					cnt += len(t1) - p
					temp.append(t2[q])
					q += 1
			return temp
		else:
			if nums[right] < nums[left]:
				cnt += 1
				(nums[left], nums[right]) = (nums[right], nums[left])
			if left ^ right:
				return [nums[left], nums[right]]
			return [nums[left]]
	merge(0, len(nums) - 1)
	if cnt > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = list(reversed(sorted(a)))
	if a == b:
		if n == len(set(a)):
			print('NO')
			continue
		print('YES')
		continue
	print('YES')


from collections import defaultdict as dd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			flag = True
	if flag:
		print('YES')
	else:
		print('NO')


tt = int(input())
for _ in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 'NO'
	for i in range(len(a) - 1):
		if not a[i] > a[i + 1]:
			ans = 'YES'
			break
	print(ans)


import bisect
import sys
from collections import defaultdict
for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	X = L[:]
	X.sort(reverse=True)
	S = set(L)
	if L == X and N == len(S):
		print('NO')
	else:
		print('YES')


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


def sol():
	n = int(input())
	arr = [int(x) for x in input().split()]
	for (i, val) in enumerate(arr):
		if i == n - 1:
			print('NO')
		elif val <= arr[i + 1]:
			print('YES')
			break

def main():
	t = int(input())
	for _ in range(t):
		sol()
main()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	y = n * (n - 1) / 2 - 1
	arr = list(map(int, input().split()))
	a = sorted(arr, reverse=True)
	b = sorted(arr)
	t = Counter(arr).most_common(1)
	if t[0][1] > 1:
		print('YES')
	elif arr == a and a != b:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	ls = list(map(int, input().split()))
	if len(set(ls)) != n:
		print('YES')
		continue
	new = [x for x in ls]
	ls.sort(reverse=True)
	ans = 'NO'
	for i in range(n):
		if ls[i] != new[i]:
			ans = 'YES'
			break
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	volumes = list(map(int, input().split()))
	x = False
	l = volumes.copy()
	l.sort(reverse=True)
	if l == volumes and len(set(volumes)) == len(volumes):
		x = True
	if x:
		print('NO')
	else:
		print('YES')


import sys
inp = sys.stdin.buffer.readline
wrl = print
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
_T_ = inin()
for _t_ in range(_T_):
	n = inin()
	a = inar()
	ans = True
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			ans = False
	if not ans:
		wrl('YES')
	else:
		wrl('NO')


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	num = len(a)
	for i in range(1, num):
		if a[i] >= a[i - 1]:
			break
	else:
		print('NO')
		continue
	print('YES')


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


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

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

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

def gets():
	return input()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count

def solve():
	for _ in range(geta()):
		n = geta()
		a = getl()
		if mergeSort(a, n) > n * (n - 1) // 2 - 1:
			print('NO')
		else:
			print('YES')
solve()


from sys import stdin
from math import ceil, gcd

def count_inv(arr):
	(arr, count) = merge_sort(arr, 0)
	return count

def merge_sort(arr, c):
	if len(arr) == 1:
		return (arr, c)
	(l, c) = merge_sort(arr[0:len(arr) // 2], c)
	(r, c) = merge_sort(arr[len(arr) // 2:], c)
	return merge(arr, l, r, c)

def merge(arr, l, r, c):
	(i, j, k) = (0, 0, 0)
	while i < len(l) and j < len(r):
		if l[i] <= r[j]:
			arr[k] = l[i]
			i += 1
		else:
			arr[k] = r[j]
			c += len(l) - i
			j += 1
		k += 1
	while i < len(l):
		arr[k] = l[i]
		i += 1
		k += 1
	while j < len(r):
		arr[k] = r[j]
		j += 1
		k += 1
	return (arr, c)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	if count_inv(arr) <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline

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

def test(ar):
	for i in range(1, len(ar)):
		if ar[i] >= ar[i - 1]:
			return True
	return False
(t,) = gt()
while t:
	t -= 1
	(n,) = gt()
	ar = gt()
	if test(ar):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	nList = list(map(int, input().split()))
	for i in range(n - 1):
		if nList[i] <= nList[i + 1]:
			ans = 'YES'
			break
		ans = 'NO'
	print(ans)


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


t = int(input())

def solve():
	l1 = []
	for i in range(n):
		l1.append(l[i])
	l1 = list(set(l))
	l1.sort(reverse=True)
	if len(l1) < n:
		return 'YES'
	else:
		if l1 == l:
			return 'NO'
		return 'YES'
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve())


t = int(input())
for i in range(t):
	totalLen = int(input())
	totalArr = list(map(int, input().split()))
	totalSwapMax = totalLen * (totalLen - 1) // 2 - 1
	co = 0
	el = totalArr[0]
	for i in range(1, len(totalArr)):
		if totalArr[i] < totalArr[i - 1]:
			co += 1
	if co == totalLen - 1:
		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 *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
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 zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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 solve():
	n = int(inp())
	ar = lis()
	if ar == sorted(ar, reverse=True):
		if len(set(ar)) == n:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')
testcase(int(inp()))


def solve():
	N = int(input())
	a = list(map(int, input().split()))
	if all((a[i] > a[i + 1] for i in range(N - 1))):
		print('NO')
	else:
		print('YES')

def main():
	T = int(input())
	for i in range(T):
		solve()
main()


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	r = 'NO'
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			r = 'YES'
			break
	print(r)


t = int(input())

def check(nums):
	for i in range(n - 1):
		if nums[i] <= nums[i + 1]:
			return False
	return True
for i in range(t):
	n = int(input())
	nums = [int(x) for x in input().split()]
	if check(nums):
		print('NO')
	else:
		print('YES')


test = int(input())
for _ in range(test):
	n = int(input())
	a = [int(u) for u in input().split()]
	possible = False
	for i in range(1, len(a)):
		if a[i] >= a[i - 1]:
			possible = True
	if possible:
		print('YES')
	else:
		print('NO')


T = int(input())
ans_ls = ['YES'] * T
for t in range(T):
	N = int(input())
	a_ls = list(map(int, input().split()))
	Decreasing = True
	for i in range(1, N):
		if a_ls[i] >= a_ls[i - 1]:
			Decreasing = False
			break
	if Decreasing:
		ans_ls[t] = 'NO'
for ans in ans_ls:
	print(ans)


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


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a1 = a[:]
	a = set(a)
	a = list(a)
	a.sort()
	a.reverse()
	if a == a1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = l.copy()
	s.sort(reverse=True)
	if l == s and len(set(l)) == n:
		print('NO')
	else:
		print('YES')


N = int(input())
l = []
for i in range(N):
	n = int(input())
	p = map(int, input().split())
	p = list(p)
	d = 'NO'
	for k in range(0, n - 1):
		if p[k] <= p[k + 1]:
			d = 'YES'
	l.append(d)
for i in range(N):
	print(l[i])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
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()
		ok = False
		for i in range(n - 1):
			if a[i] <= a[i + 1]:
				ok = True
				break
		rr.append(YES(ok))
	return JA(rr, '\n')
print(main())


import sys
import itertools as it
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	t = sorted(l, reverse=True)
	if n > 1 and len(set(l)) == n and (l == t):
		print('NO')
	else:
		print('YES')


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


import math
from datetime import date

def main():
	t = int(input())
	while t > 0:
		t -= 1
		n = int(input())
		a = [int(x) for x in input().split()]
		ok = 'True'
		for i in range(n - 1):
			if a[i] <= a[i + 1]:
				ok = 'False'
		if ok == 'True':
			print('NO')
		else:
			print('YES')
main()


import math
t = int(input())
for j in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	g = 0
	for ll in range(0, n - 1):
		if l[ll] > l[ll + 1]:
			g = 0
		else:
			g = -1
			print('YES')
			break
	if g == 0:
		print('NO')


for test in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	non_dup = set(arr)
	rev = sorted(arr, reverse=True)
	if len(non_dup) < len(arr) or rev != arr:
		print('YES')
		continue
	else:
		print('NO')
		continue
	for i in range(len(arr)):
		swapped = True
		for j in range(0, len(arr) - i - 1):
			if arr[j] > arr[j + 1]:
				(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
				swapped = False
				count += 1
		if swapped:
			break
	if n * (n - 1) // 2 - 1 <= count:
		print('NO')
	else:
		print('YES')


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


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	a = list(I())
	if len(set(a)) == n and a == sorted(a, reverse=True):
		print('NO')
	else:
		print('YES')


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = deepcopy(a)
	b.sort(reverse=True)
	c = Counter(a)
	maxx = 0
	flag = 0
	for i in c:
		if c[i] > 1:
			flag = 1
	if a == b and flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = sorted(a, reverse=True)
	(t, f) = (0, 0)
	for i in range(n):
		t += a[i] == a1[i]
		if i > 0 and a1[i] == a1[i - 1]:
			f = 1
	if t == n and f == 0:
		print('NO')
	else:
		print('YES')


def proA(arr):
	flg = False
	for i in range(len(arr) - 1):
		if arr[i] <= arr[i + 1]:
			flg = True
			break
	if flg:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	proA(arr)


import bisect
import functools
import math
T = int(input())
for Tid in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	flag = 0
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			flag = 1
	if flag:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = True
	for (i, x) in enumerate(a):
		if i + 1 < len(a) and x <= a[i + 1]:
			print('YES')
			flag = False
			break
	if flag:
		print('NO')


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = 'NO'
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			ans = 'YES'
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	i = 0
	while i < len(a) - 1 and a[i] > a[i + 1]:
		i += 1
	if i == len(a) - 1:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	a = list(map(int, input().strip().split(' ')))
	p = []
	for j in a:
		p.append(j)
	p.sort(reverse=True)
	if p == a and len(list(set(a))) == n:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	for i in range(1, n):
		if A[i - 1] > A[i]:
			continue
		else:
			print('YES')
			break
	else:
		print('NO')


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

def results(arr, n):
	tmp = sorted(arr)
	for i in range(n - 1):
		if tmp[i] == tmp[i + 1]:
			return 'YES'
	if arr != tmp[::-1]:
		return 'YES'
	return 'NO'

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		a = seq()
		result = results(a, n)
		print(result)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = 0
	f = 0
	for i in range(len(l)):
		if l[i] <= l[i + 1]:
			f = 1
		if i == n - 2:
			break
	if f:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().rstrip().split()))
	l = sorted(arr, reverse=True)
	if len(set(arr)) == n and arr == l:
		print('NO')
	else:
		print('YeS')


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


import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
import heapq
INF = 10 ** 20
MOD = 10 ** 9 + 7
ni = lambda : int(sys.stdin.readline().rstrip())
ns = lambda : map(int, sys.stdin.readline().rstrip().split())
na = lambda : list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda : list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
flush = lambda : sys.stdout.flush()

def main():
	t = ni()
	for _ in range(t):
		n = ni()
		a = na()
		flg = False
		for i in range(1, n):
			if a[i - 1] <= a[i]:
				flg = True
				break
		print('YES' if flg else 'NO')
main()


def possible(l):
	total = 0
	c = len(l)
	for i in range(c - 1):
		if l[i] <= l[i + 1]:
			return True
	return False

def prob():
	n = int(input())
	l = list(map(int, input().split()))
	if possible(l):
		print('YES')
	else:
		print('NO')
n = int(input())
for _ in range(n):
	prob()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == n and sorted(a, reverse=True) == a:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	solve()


test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = False
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	a = int(input())
	b = list(map(int, input().split()))
	if sorted(b, reverse=True) == b and len(set(b)) == a:
		print('NO')
	else:
		print('YES')


def is_rev(xs):
	for i in range(len(xs) - 1):
		if xs[i] <= xs[i + 1]:
			return False
	return True
for tc in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	t = 0
	if is_rev(s):
		print('NO')
	else:
		print('YES')


import copy
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = copy.copy(l)
	l1.sort(reverse=True)
	f = 0
	for j in range(n - 1):
		if l[j] == l[j + 1]:
			print('YES')
			f = 1
			break
	if f == 0:
		if l == l1:
			print('NO')
		else:
			print('YES')


try:
	for t in range(int(input())):
		n = int(input())
		if 2 <= n <= 50000:
			l = [int(x) for x in input().split()][:n]
			ans = 'NO'
			for i in range(1, len(l)):
				if l[i - 1] <= l[i]:
					ans = 'YES'
					break
			print(ans)
except:
	pass


t = int(input())

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


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		values = list(map(int, input().split()))
		stop = True
		for i in range(1, n):
			if values[i] >= values[i - 1]:
				stop = False
				break
		if stop:
			print('NO')
		else:
			print('YES')
main()


def mergesort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1):
		arr[i] = temp_arr[i]
	return inv_count
for _ in range(int(input())):
	n = int(input())
	req = n * (n - 1) // 2 - 1
	arr = list(map(int, input().split()))
	n = len(arr)
	if mergesort(arr, n) > req:
		print('NO')
	else:
		print('YES')


import sys, io, os, time
from collections import defaultdict
from collections import Counter
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())
	arr = list(map(int, input().split()))
	f = 1
	for i in range(n - 1):
		f &= arr[i] > arr[i + 1]
	if f:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l = n * (n - 1) // 2 - 1
	A = list(map(int, input().split()))
	c = 0
	for i in range(1, len(A)):
		if A[i - 1] <= A[i]:
			c = 1
			break
	if c == 1:
		print('YES')
	else:
		print('NO')


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


import os
import sys
from math import *
from collections import *
from bisect 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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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()
	b = sorted(a, reverse=True)
	ans = 'YES'
	if len(set(a)) == n and a == b:
		ans = 'NO'
	print(ans)


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


class All:

	def __init__(self):
		self.n = int(input())
		self.lst = list(map(int, input().split()))

	def solution(self):
		ct = 0
		for i in range(len(self.lst) - 1):
			if self.lst[i] > self.lst[i + 1]:
				ct += 1
		if ct + 1 == self.n:
			return False
		else:
			return True
t = int(input())
for _ in range(t):
	inp = All()
	if inp.solution():
		print('YES')
	else:
		print('NO')


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


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


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			fl = True
		else:
			fl = False
			break
	if sorted(a, reverse=True) == a and max(a) != min(a) and fl:
		print('No')
	else:
		print('Yes')


gans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	w = sorted(u)
	s = set(u)
	w.reverse()
	if u != w or len(s) != n:
		gans.append('YES')
	else:
		gans.append('NO')
print('\n'.join(gans))


import sys

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

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


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) < n:
		print('YES')
	else:
		flag = False
		prev = float('inf')
		for i in range(n):
			if prev < arr[i]:
				flag = True
				break
			prev = arr[i]
		if flag:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	target = n * (n - 1) // 2 - 1
	ans = 0
	stack = [nums[0]]
	for i in range(1, n):
		if nums[i] < stack[-1]:
			ans += len(stack)
		else:
			while stack and stack[-1] <= nums[i]:
				stack.pop()
		stack.append(nums[i])
	if ans > target:
		print('NO')
	else:
		print('YES')


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


n = int(input())
for i in range(n):
	s = 'NO'
	size = int(input())
	time = size * (size - 1) // 2 - 1
	vals = [int(x) for x in input().split()]
	for f in range(size - 1):
		if vals[f] <= vals[f + 1]:
			s = 'YES'
			break
	print(s)


from collections import Counter
for z in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	r = Counter(l)
	m = l.copy()
	m.sort(reverse=True)
	res = 'NO'
	for i in r.values():
		if i > 1:
			res = 'YES'
			break
	for i in range(n):
		if m[i] != l[i]:
			res = 'YES'
			break
	print(res)


import heapq as hq
from heapq import heappop, heappush
from collections import deque, defaultdict, Counter
from sys import stdin, stdout

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

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

def insr():
	return list(stdin.readline().strip())

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

def subset_sum_count(arr, n, sum):
	dp = [[0 for _ in range(sum + 1)] for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(sum + 1):
			if j == 0:
				dp[i][j] = 1
			elif arr[i - 1] <= j:
				dp[i][j] = dp[i - 1][j - arr[i - 1]] + dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[n][sum]

def binary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		mi = lo + (hi - lo) / 2
		if func(mi):
			hi = mi
		else:
			lo = mi
	return (lo + hi) / 2

def ternary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		lo_third = lo + (hi - lo) / 3
		hi_third = hi - (hi - lo) / 3
		if func(lo_third) < func(hi_third):
			lo = lo_third
		else:
			hi = hi_third
	return (lo + hi) / 2

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def discrete_ternary_search(func, lo, hi):
	while lo <= hi:
		lo_third = lo + (hi - lo) // 3
		hi_third = lo + (hi - lo) // 3 + (1 if 0 < hi - lo < 3 else (hi - lo) // 3)
		if func(lo_third) < func(hi_third):
			lo = lo_third + 1
		else:
			hi = hi_third - 1
	return lo
	return -1

def right_rotate(a, s):
	return a[s:] + a[:s]

def dec_to_bin(x):
	return int(bin(x)[2:])

def str_to_integer_list(n):
	a = []
	for i in range(len(n)):
		a.append(int(n[i]))
	return a

def list_to_str(l):
	s = ''
	for i in l:
		s += str(i)
	return s

def dijkstra(s, N, E):
	visited = set()
	dist = {}
	for i in range(1, N + 1):
		dist[i] = 1 << 29
	queue = [(dist[i], i) for i in range(1, N + 1)]
	hq.heappush(queue, (0, s))
	dist[s] = 0
	while queue:
		(d, u) = hq.heappop(queue)
		if u in visited:
			continue
		for t in E[u]:
			(v, r) = t
			if dist[v] > d + r:
				dist[v] = d + r
				hq.heappush(queue, (dist[v], v))
		visited.add(u)
	return dist

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def dijkstra(n, graph, start):
	(dist, parents) = ([float('inf')] * n, [-1] * n)
	dist[start] = 0
	queue = [(0, start)]
	while queue:
		(path_len, v) = heappop(queue)
		if path_len == dist[v]:
			for (w, edge_len) in graph[v]:
				if edge_len + path_len < dist[w]:
					(dist[w], parents[w]) = (edge_len + path_len, v)
					heappush(queue, (edge_len + path_len, w))
	return (dist, parents)

def path(start, end, parent):
	path = [end]
	while path[-1] != start:
		path.append(parent[path[-1]])
	path.reverse()
	return path

def bfs(graph, start, goal):
	if start == goal:
		return [start]
	visited = {start}
	queue = deque([(start, [])])
	while queue:
		(current, path) = queue.popleft()
		visited.add(current)
		for neighbor in graph[current]:
			if neighbor == goal:
				return path + [current, neighbor]
			if neighbor in visited:
				continue
			queue.append((neighbor, path + [current]))
			visited.add(neighbor)
	return None

def fillPrefixSum(arr, n, prefixSum):
	prefixSum[0] = arr[0]
	for i in range(1, n):
		prefixSum[i] = prefixSum[i - 1] + arr[i]

def check(a, ind, d1):
	beg = a[:ind + 1]
	end = a[ind + 1:]
	d = []
	c = 0
	for i in end:
		if i - d1 in beg:
			c += 1
	return c
import os
import sys
from io import BytesIO, IOBase

def DecimalToBinary(n):

	def helper(n):
		if n == 0:
			return ''
		else:
			if n % 2 == 1:
				binaryDigit = '1'
			else:
				binaryDigit = '0'
			return helper(n // 2) + binaryDigit
	if n == 0:
		result = '0'
	else:
		result = helper(n)
	return result

def p(board):
	for i in range(8):
		s = ''
		for j in range(8):
			s += board[i][j]
		print(s)

def binaryToDecimal(n):
	return int(n, 2)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def solve(a, b):
	x = DecimalToBinary(a)
	y = DecimalToBinary(b)
	z = x + y
	l = y + x
	r = binaryToDecimal(z) - binaryToDecimal(l)
	return r

def mostFrequent(arr, n):
	arr.sort()
	max_count = 1
	res = arr[0]
	curr_count = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			curr_count += 1
		else:
			if curr_count > max_count:
				max_count = curr_count
				res = arr[i - 1]
			curr_count = 1
	if curr_count > max_count:
		max_count = curr_count
		res = arr[n - 1]
	return res
from bisect import bisect_right, bisect_left

def lds(arr, n):
	lds = [0] * n
	max = 0
	for i in range(n):
		lds[i] = 1
	for i in range(1, n):
		for j in range(i):
			if arr[i] < arr[j] and lds[i] < lds[j] + 1:
				lds[i] = lds[j] + 1
	for i in range(n):
		if max < lds[i]:
			max = lds[i]
	return max
import math

def prefix(a):
	pre = []
	pre.append(a[0])
	for i in range(1, len(a)):
		pre.append(pre[i - 1] + a[i])
	return pre

def solve(n, x, size):
	res = 10000000
	if n == 0:
		return 0
	if size == 0:
		return 0
	for i in x:
		res = 1 + min(res, solve(n - i, x, size - 1))
		return res

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count

def main():
	for _ in range(inp()):
		n = inp()
		a = inlt()
		d = n * (n - 1) // 2 - 1
		if mergeSort(a, n) <= d:
			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())
	ar = list(map(int, input().split()))
	br = ar.copy()
	cr = ar.copy()
	cr.sort()
	br.sort(reverse=True)
	if ar == br and ar != cr and (len(set(ar)) == n):
		print('NO')
	else:
		print('YES')


t = int(input())
w = []
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	rr = sorted(r)
	rrr = rr[::-1]
	if r != rrr:
		w.append('YES')
	else:
		c = 0
		for i in range(n - 1):
			if rr[i] == rr[i + 1]:
				c = 1
				break
		if c == 1:
			w.append('YES')
		else:
			w.append('NO')
for j in w:
	print(j)


t = int(input())
for q in range(t):
	n = int(input())
	mass = [int(x) for x in input().split()]
	f = False
	for i in range(n - 1, 0, -1):
		if mass[i] >= mass[i - 1]:
			f = True
			break
	if f:
		print('YES')
	else:
		print('NO')


N = int(input())
for _ in range(N):
	ns = int(input())
	arr = list(map(int, input().split()))
	stamp = arr[0]
	printed = False
	for i in range(1, ns):
		if arr[i] >= stamp:
			print('YES')
			printed = True
			break
		stamp = arr[i]
	if not printed:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = sorted(l, reverse=True)
	c = 0
	for i in range(n):
		if l[i] == x[i]:
			c = c + 1
			continue
		else:
			break
	if len(set(l)) <= n - 1:
		print('YES')
	elif c == n:
		print('NO')
	else:
		print('YES')


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	b.reverse()
	ans = 'NO'
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			ans = 'YES'
			break
	if ans == 'NO':
		if a == b:
			ans = 'NO'
		else:
			ans = 'YES'
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = len(set(a))
	inc = sorted(a)
	dec = inc[::-1]
	if a == inc:
		print('YES')
	elif a == dec and k == n:
		print('NO')
	else:
		print('YES')


def lowbit(x: int):
	return x & -x

def treearray_update(pos: int, x: int, array: list):
	while pos < len(array):
		array[pos] += x
		pos += lowbit(pos)

def treearray_getsum(pos: int, array: list) -> int:
	ans = 0
	while pos > 0:
		ans += array[pos]
		pos -= lowbit(pos)
	return ans

def calcinvs(array: list):
	d = {}
	for (k, v) in enumerate(sorted(array)):
		d[v] = k + 1
	treearray = [0 for i in range(1 + len(array))]
	invs = 0
	for i in array:
		invs += treearray_getsum(len(treearray) - 1, treearray) - treearray_getsum(d[i], treearray)
		treearray_update(d[i], 1, treearray)
	return invs
import math
t = int(input())
for _ in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	invs = calcinvs(li)
	if invs <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = n * (n - 1) // 2 - 1
	b = sorted(a, reverse=True)
	if b == a and len(a) == len(set(a)):
		print('NO')
	else:
		print('YES')


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	arr = list(map(int, input().split()))
	dic = {}
	if n == 2:
		if arr == sorted(arr):
			print('YES')
		else:
			print('NO')
	else:
		flag = 0
		for i in arr:
			try:
				dic[i] += 1
				if dic[i] > 1:
					flag = 1
					break
			except:
				dic[i] = 1
		if flag:
			print('YES')
		elif arr == sorted(arr, reverse=True):
			print('NO')
		else:
			print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	x = [int(i) for i in input().split()]
	flag = False
	for i in range(0, len(x) - 1):
		if x[i] <= x[i + 1]:
			print('YES')
			flag = True
			break
	if flag == False:
		print('NO')


def check(nums, n):
	for i in range(1, n):
		if nums[i - 1] <= nums[i]:
			return 'YES'
	return 'NO'
test_cases = int(input())
for test in range(test_cases):
	n = int(input())
	nums = list(map(int, input().split()))
	print(check(nums, n))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = arr.copy()
	arr1.sort(reverse=True)
	if arr1 != arr or len(arr) != len(set(arr)):
		print('Yes')
	else:
		print('No')


a = int(input())
for i in range(a):
	b = int(input())
	c = [int(x) for x in input().split()]
	count = 0
	for j in range(1, b):
		if c[j - 1] > c[j]:
			count = count + 1
	if count == b - 1:
		print('NO')
	else:
		print('YES')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	d = defaultdict(lambda : 0)
	for i in a:
		d[i] += 1
	n1 = len(d)
	if a == b and n1 == n:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	flag = 'NO'
	for x in range(1, n):
		if a[x - 1] <= a[x]:
			flag = 'YES'
			break
	print(flag)


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


def countMergeSort(arr, start, end):
	if start >= end:
		return (0, arr[start:end + 1])
	if start == end - 1:
		if arr[start] > arr[end]:
			return (1, [arr[end], arr[start]])
		else:
			return (0, arr[start:end + 1])
	mid = (start + end) // 2
	(lSwaps, lSorted) = countMergeSort(arr, start, mid)
	(rSwaps, rSorted) = countMergeSort(arr, mid + 1, end)
	mSwaps = 0
	sortedArr = []
	(lIndex, rIndex) = (0, 0)
	while lIndex < len(lSorted) and rIndex < len(rSorted):
		if lSorted[lIndex] <= rSorted[rIndex]:
			sortedArr.append(lSorted[lIndex])
			lIndex += 1
		else:
			sortedArr.append(rSorted[rIndex])
			rIndex += 1
			mSwaps += len(lSorted) - lIndex
	sortedArr += lSorted[lIndex:]
	sortedArr += rSorted[rIndex:]
	totalSwaps = lSwaps + rSwaps + mSwaps
	return (totalSwaps, sortedArr)

def count_inversions(a):
	return countMergeSort(a, 0, len(a) - 1)[0]
for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split(' ')))
	mini = count_inversions(arr)
	if n % 2 == 0:
		calc = n / 2 * (n - 1)
	else:
		calc = n * ((n - 1) / 2)
	if calc - 1 < mini:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = sorted(arr, reverse=True)
	if arr == s and len(set(arr)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	edge = n * (n - 1) / 2 - 1
	cubes = list(map(int, input().split()))
	if sorted(cubes) == cubes:
		print('YES')
	elif edge == 0:
		print('NO')
	elif len(set(cubes)) != len(cubes):
		print('YES')
	elif cubes == sorted(cubes, reverse=True):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	k = lst.copy()
	sets = set(lst)
	if len(sets) < len(lst):
		print('YES')
		continue
	else:
		lst.sort(reverse=True)
		if lst == k:
			print('NO')
		else:
			print('YES')


cases = int(input())
while cases:
	cases -= 1
	num = int(input())
	arr = list(map(int, input().split()))
	rev = sorted(arr, reverse=True)
	if len(set(arr)) == num and arr == rev:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

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

def listStr():
	return list(input().strip())
import collections as col
import math, itertools

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count

def solve():
	N = getInt()
	A = getInts()
	inv = mergeSort(A, N)
	if inv <= N * (N - 1) // 2 - 1:
		return 'YES'
	return 'NO'
for _ in range(getInt()):
	print(solve())


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


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if l == sorted(l):
		print('YES')
	elif l == sorted(l)[::-1]:
		i = 0
		cnt = 0
		l.reverse()
		while i < n:
			z = l[i]
			count = 0
			while l[i] == z:
				count += 1
				i += 1
				if i == n:
					break
			cnt += count * (n - i)
		if cnt <= n * (n - 1) // 2 - 1:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = a[:]
	k.sort()
	if k[::-1] != a or len(set(a)) != n:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	s = set(l)
	if len(l) == len(s):
		if l == sorted(l):
			print('YES')
		else:
			l2 = sorted(l, reverse=True)
			if l == l2:
				print('NO')
			else:
				print('YES')
	else:
		print('YES')


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
t = ii1()
for i in range(t):
	n = ii1()
	arr = iia()
	ans = countSwaps(arr, n)
	if ans > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


TC = int(input())
for tc in range(TC):
	N = int(input())
	A = list(map(int, input().split()))
	p = A[0]
	result = False
	for a in A[1:]:
		if p <= a:
			result = True
			break
		p = a
	if result:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	x = 0
	if n == 1:
		print('Yes')
	else:
		for i in range(n - 1):
			if arr[i] <= arr[i + 1]:
				x = 1
				break
		if x:
			print('Yes')
		else:
			print('No')


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


from sys import stdin
input = stdin.buffer.readline

def solve(n, lst):
	(noDiff, noGreater) = (False, False)
	for i in range(n - 1):
		if lst[i] < lst[i + 1]:
			noGreater = True
		if lst[i] == lst[i + 1]:
			noDiff = True
	if not noDiff and (not noGreater):
		return 'NO'
	else:
		return 'YES'
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


import math
n = int(input())
for i in range(n):
	m = int(input())
	s = input().split(' ')
	a = []
	for item in s:
		a.append(int(item))
	f = False
	for i in range(m - 1):
		if a[i] <= a[i + 1]:
			f = True
	a.sort()
	if f or a[0] == a[-1]:
		print('YES')
	else:
		print('NO')


import sys
import bisect
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 T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			ans = True
			break
	if ans:
		print('YES')
	else:
		print('NO')


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


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	lol = 0
	for i in range(1, n):
		if l[i - 1] <= l[i]:
			lol = 1
			break
	if lol:
		print('YES')
	else:
		print('NO')
	t -= 1


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()]
	for i in range(n - 1):
		if aa[i] <= aa[i + 1]:
			print('YES')
			return
	print('NO')

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


from sys import stdin, stdout
import math
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	n = I()
	a = L()
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			print('YES')
			return
	print('NO')
for _ in range(I()):
	solve()


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	k = n * (n - 1) // 2 - 1
	st = False
	for i in range(1, n):
		if li[i] >= li[i - 1]:
			st = True
			break
	if st == True:
		print('YES')
	else:
		print('NO')


import sys, os
from difflib import SequenceMatcher
from collections import Counter
from bisect import bisect_left as bl, bisect_right as br
from io import BytesIO, IOBase
from itertools import accumulate
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 memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def memoize(f):

	class memodict(dict):

		def __getitem__(self, *key):
			return dict.__getitem__(self, key)

		def __missing__(self, key):
			ret = self[key] = f(*key)
			return ret
	return memodict().__getitem__
LCSubstr = lambda a, b: SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))

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

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def extended_gcd(a, b):
	(s, old_s) = (0, 1)
	(r, old_r) = (b, a)
	while r:
		q = old_r // r
		(old_r, r) = (r, old_r - q * r)
		(old_s, s) = (s, old_s - q * s)
	return (old_r, old_s, (old_r - old_s * a) // b if b else 0)

def modinv(a, m):
	(g, x, _) = extended_gcd(a % m, m)
	return x % m if g == 1 else None

def make_nCr_mod(max_n=2 * 10 ** 5, mod=10 ** 9 + 7):
	max_n = min(max_n, mod - 1)
	(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

	def nCr_mod(n, r):
		res = 1
		while n or r:
			(a, b) = (n % mod, r % mod)
			if a < b:
				return 0
			res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
			n //= mod
			r //= mod
		return res
	return nCr_mod

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
			r = mid - 1
	return -1

def PrefixSum(arr):
	return list(accumulate(arr))

class inputs:

	def single(self):
		return int(input())

	def mul(self):
		return map(int, input().split())

	def list(self):
		return list(map(int, input().split()))
inp = inputs()

def main():
	for t in range(int(input())):
		n = inp.single()
		a = inp.list()
		l = a.copy()
		l.sort(reverse=True)
		flag = 0
		for i in range(len(a)):
			if l[i] != a[i]:
				flag = 1
				break
		if flag == 0 and len(set(l)) == len(l):
			print('NO')
		else:
			print('YES')
main()


T = int(input())
for z in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = a.copy()
	b.sort(reverse=True)
	b2 = list(set(a))
	if len(a) != len(b2):
		a = []
	if a == b:
		print('NO')
	else:
		print('YES')


t = int(input())
for l in range(t):
	n = int(input())
	listx = list(map(int, input().split()))
	lm = sorted(listx)
	lmr = lm[::-1]
	if lmr == listx and len(set(listx)) == n:
		print('NO')
	else:
		print('YES')


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import *
from math import *
for _ in range(int(read())):
	n = int(read())
	nums = list(readi())
	sortedNums = sorted(nums, reverse=True)
	count = defaultdict(int)
	for i in nums:
		count[i] += 1
	maxKey = max(count, key=count.get)
	if sortedNums == nums and count[maxKey] == 1:
		print('NO')
	else:
		print('YES')


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

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 find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

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


def solve():
	n = int(input())
	ans = 0
	arr = [int(v) for v in input().split()]
	if len(set(arr)) == n and sorted(arr, reverse=True) == arr:
		print('NO')
	else:
		print('YES')
t = int(input())
for _ in range(t):
	solve()


def countSwaps(arr, n):
	for i in range(0, n - 1):
		if arr[i + 1] >= arr[i]:
			return 'Yes'
	return 'No'
T = int(input())
while T:
	N = int(input())
	A = list(map(int, input().split()))
	print(countSwaps(A, len(A)))
	T -= 1


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
from itertools import accumulate

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 Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)

def solution():
	for _ in range(Int()):
		n = Int()
		a = List()
		c = countSwaps(a, n)
		if c > n * (n - 1) // 2 - 1:
			print('NO')
		else:
			print('YES')
solution()


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	aSortedReversed = sorted(ar, reverse=True)
	ans = 'No'
	for i in range(n - 1):
		if aSortedReversed[i] == aSortedReversed[i + 1]:
			ans = 'Yes'
			break
	if ar != aSortedReversed:
		print('Yes')
	else:
		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')
import math
import bisect
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 2:
		if arr == sorted(arr):
			print('YES')
		else:
			print('NO')
	elif n == 1:
		print('YES')
	else:
		l = len(set(arr))
		if arr == sorted(arr):
			print('YES')
		elif arr == sorted(arr)[::-1] and l == len(arr):
			print('NO')
		else:
			print('YES')


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


import sys, os, io

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')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
N = 1000000
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = ria()
		z = sorted(a)[::-1]
		if a == z and len(set(a)) == n:
			print('NO')
		else:
			print('YES')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from collections import *
from itertools import *
from bisect import *

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

def arrinp():
	return [int(x) for x in input().split()]

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		A = arrinp()
		max_c = n * (n - 1) // 2 - 1
		non_decreasing = False
		for i in range(n - 1):
			if A[i] > A[i + 1]:
				pass
			else:
				non_decreasing = True
				break
		if non_decreasing:
			print('YES')
		else:
			print('NO')
main()


def merge(arr):
	if len(arr) > 1:
		global c
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		merge(L)
		merge(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] <= R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
				c += len(L) - i
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
for _ in range(int(input())):
	c = 0
	n = int(input())
	a = [int(x) for x in input().split()]
	b = int(n * (n - 1) / 2 - 1)
	merge(a)
	if c <= b:
		print('YES')
	else:
		print('NO')


for i1 in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 2:
		if l[0] > l[1]:
			print('NO')
		else:
			print('YES')
	else:
		dict = {}
		for i in l:
			dict[i] = 0
		for i in l:
			dict[i] += 1
		flag = 0
		for i in dict.values():
			if i > 1:
				flag = 1
				break
		if flag == 1:
			print('YES')
			continue
		a = l.copy()
		a.sort(reverse=True)
		if a == l:
			print('NO')
		else:
			print('YES')


t = int(input())
for h in range(t):
	k = int(input())
	n = list(map(int, input().split()))
	xmin = k * (k - 1) - 2
	xmin = xmin / 2
	nsort = n[:]
	nsort.sort()
	nsort = nsort[::-1]
	if n == nsort:
		if len(set(n)) < k:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


t = 1
t = int(input())
from collections import Counter
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	aC = Counter(a)
	b = sorted(a, reverse=True)
	if a != b or max(aC.values()) > 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	tmp = False
	for j in range(1, n):
		if lst[j - 1] <= lst[j]:
			tmp = True
	print(['NO', 'YES'][tmp])


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	possible = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			possible = True
			break
	if possible == False:
		print('NO')


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	a = list(l)
	flg = 0
	d = dd(int)
	for i in l:
		d[i] += 1
		if d[i] == 2:
			flg = 1
	a.sort(reverse=True)
	for i in range(n):
		if a[i] != l[i]:
			flg = 1
			break
	if flg:
		print('YES')
	else:
		print('NO')


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

def main():
	t = int(input())
	for _ in range(t):
		case()
main()


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


t = int(input())
for i in range(t):
	n = int(input())
	w = [int(k) for k in input().split()]
	if sorted(w) != w[::-1] or len(set(w)) != len(w):
		print('YES')
	else:
		print('NO')


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	print('YNEOS'[sum((a > b for (a, b) in zip(s, s[1:]))) == n - 1::2])


for i in range(int(input())):
	(a, s) = (int(input()), [int(x) for x in input().split()])
	print({0: 'YES', 1: 'NO'}[s == list(sorted(s, reverse=True)) and len(set(s)) == a])


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mn = min(a)
	b = list(set(a))
	x = 0
	if len(b) == n:
		for i in range(len(a) - 1):
			if a[i] > a[i + 1]:
				continue
			else:
				x = 1
				break
		if x == 0:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for j in range(n - 2, -1, -1):
		if arr[j] <= arr[j + 1]:
			print('YES')
			break
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split(' ')]
	lst2 = sorted(lst, reverse=True)
	if lst == lst2 and len(lst) == len(set(lst2)):
		print('NO')
	else:
		print('YES')


from math import ceil
from decimal import *

def get_ans(n, arr):
	for i in range(n - 1):
		if arr[i] <= arr[i + 1]:
			return 'YES'
	return 'NO'
t = int(input())
anss = []
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	anss.append(get_ans(n, arr))
for j in anss:
	print(j)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	need = sorted(arr)
	if need == arr:
		print('YES')
		continue
	c = sorted(arr, reverse=True)
	d = list(set(arr))
	if arr == c and len(d) == n:
		print('NO')
	else:
		print('YES')


import sys
import math
mod = 998244353
dynamic_factorial = False

def main(test_case=False):
	n = int(input()) if test_case else 1
	for _ in range(n):
		test()
		print()

def fast_pow(a: int, b: int):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def c2(n):
	return n * (n - 1) // 2

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

def bits(n: int):
	return list(bin(n)).count('1')

def flush():
	sys.stdout.flush()

def parr(arr):
	print(*arr, sep=' ')

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

def ext_gcd(a: int, b: int):
	if b == 0:
		return [a, [1, 0]]
	res = ext_gcd(b, a % b)
	g = res[0]
	if g != 1:
		return False
	x1 = res[1][0]
	y1 = res[1][1]
	x = y1
	y = x1 - y1 * (a // b)
	return [g, [x, y]]

def get_set(a):
	res = {}
	for x in a:
		if x in res:
			res[x] += 1
		else:
			res[x] = 1
	return res
fact = {0: 1}

def factorial(n):
	if dynamic_factorial:
		if n not in fact:
			fact[n] = factorial(n - 1) * n
		return fact[n]
	else:
		res = 1
		while n > 0:
			res = res * n % mod
			n -= 1
		return res

def sum_of(a):
	res = 0
	for x in a:
		res = (res + x) % mod
	return res

def prod_of(a):
	res = 1
	for x in a:
		res = res * x % mod
	return res

def test():
	n = get()[0]
	a = list(get())
	b = sorted(a)[::-1]
	i = 0
	while i < n - 1:
		if b[i] == b[i + 1]:
			print('YES')
			return
		i += 1
	if b == a:
		print('NO')
	else:
		print('YES')
main(test_case=True)


for j in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	flag = 'No'
	for i in range(n - 1):
		if l[i + 1] >= l[i]:
			flag = 'YES'
			break
	print(flag)


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


import sys
import math

def master():
	(n, l) = (II(), LI())
	for i in range(1, len(l)):
		if l[i] >= l[i - 1]:
			print('YES')
			return
	print('NO')
	return

def main():
	_v_ = II()
	for ___ in range(_v_):
		master()
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

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]
main()


for ij in range(0, int(input())):
	n1 = int(input())
	l = list(map(int, input().split(' ')))
	o = 0
	for i in range(0, len(l) - 1):
		if l[i] <= l[i + 1]:
			o = 1
			break
	if o:
		print('YES')
	else:
		print('NO')


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

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

def iinp():
	return int(input())

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

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

def p(a):
	print(a)
for _ in range(iinp()):
	n = iinp()
	v = linp()
	f = 0
	if len(v) != len(set(v)):
		print('YES')
		f = 1
	if f == 0:
		b = v.copy()
		v.reverse()
		b.sort()
		if b == v:
			print('NO')
		else:
			print('YES')


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = []
	c = 0
	b = a[:]
	count = 0
	flag = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			flag = 1
			break
	if flag == 1:
		print('YES')
		continue
	a.sort(reverse=True)
	for i in range(n):
		if a[i] == b[i]:
			count += 1
	if count == n:
		print('NO')
	else:
		print('YES')


def merge(arr, L, R):
	i = il = ir = inversion_count = 0
	l_len = len(L)
	r_len = len(R)
	while il < l_len and ir < r_len:
		if L[il] <= R[ir]:
			arr[i] = L[il]
			il += 1
		else:
			arr[i] = R[ir]
			ir += 1
			inversion_count += l_len - il
		i += 1
	while il < l_len:
		arr[i] = L[il]
		il += 1
		i += 1
	while ir < r_len:
		arr[i] = R[ir]
		ir += 1
		i += 1
	return inversion_count

def merge_sort(arr):
	mid = len(arr) // 2
	inversion_count = 0
	if mid > 0:
		L = arr[:mid]
		R = arr[mid:]
		inversion_count += merge_sort(L)
		inversion_count += merge_sort(R)
		inversion_count += merge(arr, L, R)
	return inversion_count
for _ in range(int(input())):
	N = int(input())
	a = list(map(int, input().split()))
	condition = N * (N - 1) // 2 - 1
	x = merge_sort(a)
	if x <= condition:
		print('YES')
	else:
		print('NO')


def get(a):
	if len(list(set(a))) != len(a):
		return 1
	if list(reversed(sorted(a))) != a:
		return 1
	return 0

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		print(['NO', 'YES'][get(a)])
main()


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()))
		ans = 'NO'
		for i in range(1, n):
			if arry[i] >= arry[i - 1]:
				ans = 'YES'
				break
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	good = False
	for j in range(n - 1):
		if arr[j] <= arr[j + 1]:
			print('YES')
			good = True
			break
	if not good:
		print('NO')


import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		if len(set(a)) == len(a) and sorted(a, reverse=True) == a:
			print('NO')
		else:
			print('YES')
en = enumerate
FIO = 10

def debug(*args, c=6):
	pass
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=sys.stderr)
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

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))

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


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
from itertools import accumulate
from functools import lru_cache
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()
	l1 = sorted(l)
	print('YES' if l != l1[::-1] or l == l1 or len(set(l)) != n else 'NO')


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if a == sorted(a)[::-1] and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


n = int(input())
ans = list()
for _ in range(n):
	t = int(input())
	l = [int(i) for i in input().split()]
	a = False
	for i in range(len(l) - 1):
		if l[i] <= l[i + 1]:
			a = True
			break
	if a:
		ans.append('YES')
	else:
		ans.append('NO')
for a in ans:
	print(a)


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


for _ in range(int(input())):
	t = int(input())
	l = [int(x) for x in input().split()]
	k = l.copy()
	k.sort(reverse=True)
	flag = 0
	if k == l and len(set(l)) == t:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
from math import *
testing = True

def tp(*args):
	pass
if testing:
	tp = print

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		a = [int(i) for i in stdin.readline().split()]
		rev = sorted(a, reverse=True)
		possible = True
		s = set(a)
		if a == rev and len(s) == n:
			possible = False
		if not possible:
			print('NO')
		else:
			print('YES')
main()


def countMergeSort(arr, start, end):
	if start >= end:
		return (0, arr[start:end + 1])
	if start == end - 1:
		if arr[start] > arr[end]:
			return (1, [arr[end], arr[start]])
		else:
			return (0, arr[start:end + 1])
	mid = (start + end) // 2
	(lSwaps, lSorted) = countMergeSort(arr, start, mid)
	(rSwaps, rSorted) = countMergeSort(arr, mid + 1, end)
	mSwaps = 0
	sortedArr = []
	(lIndex, rIndex) = (0, 0)
	while lIndex < len(lSorted) and rIndex < len(rSorted):
		if lSorted[lIndex] <= rSorted[rIndex]:
			sortedArr.append(lSorted[lIndex])
			lIndex += 1
		else:
			sortedArr.append(rSorted[rIndex])
			rIndex += 1
			mSwaps += len(lSorted) - lIndex
	sortedArr += lSorted[lIndex:]
	sortedArr += rSorted[rIndex:]
	totalSwaps = lSwaps + rSwaps + mSwaps
	return (totalSwaps, sortedArr)

def count_inversions(a):
	return countMergeSort(a, 0, len(a) - 1)[0]
t = int(input())
for u in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = count_inversions(arr)
	if ans <= n * (n - 1) // 2 - 1:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print('YES')
		continue
	if sorted(arr, reverse=True) == arr:
		if len(set(arr)) == n:
			print('NO')
			continue
	print('YES')
	continue


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


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


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


for i in range(int(input())):
	n = int(input())
	data = [int(x) for x in input().split()]
	d = sorted(data)[::-1]
	flag = 1
	for i in range(1, n):
		if d[i] == d[i - 1]:
			flag = 0
	if data == d and flag:
		print('NO')
	else:
		print('YES')


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


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ra = sorted(a)
	if len(set(a)) != len(a):
		print('YES')
	elif a == ra[::-1]:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	arr2 = arr.copy()
	arr2.sort(reverse=True)
	if len(s) == n and arr2 == arr:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	rev = sorted(lis, reverse=True)
	con_du = True
	if len(set(lis)) == len(lis):
		con_du = False
	if lis == rev and (not con_du):
		print('NO')
	else:
		print('YES')


import sys
MOD = 1000000007

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

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

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

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

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

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergeSort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergeSort(arr, temp, left, mid)
		inv_count += _mergeSort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def countSwaps(arr, n):
	temp = [0 for i in range(n)]
	return _mergeSort(arr, temp, 0, n - 1)
for _ in range(Int()):
	n = Int()
	arr = Array()
	maximum = n * (n - 1) / 2 - 1
	if countSwaps(arr, n) > maximum:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	line = input()
	pui = line.split()
	ar = [int(i) for i in pui]
	temp1 = True
	temp2 = True
	for i in range(n - 1):
		if ar[i] != ar[i + 1]:
			temp1 = False
			break
	if temp1:
		print('YES')
		continue
	for i in range(n - 1):
		if ar[i] <= ar[i + 1]:
			temp2 = False
			break
	if temp2:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	A = int(input())
	B = list(map(int, input().split()))
	for j in range(len(B) - 1):
		if B[j] <= B[j + 1]:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	printed = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			printed = True
			break
	if not printed:
		print('NO')


p = int(input())
while p:
	n = int(input())
	arr = list(map(int, input().split()))
	if len(arr) == len(set(arr)) and arr == sorted(arr, reverse=True):
		print('NO')
	else:
		print('YES')
	p -= 1


import sys
try:
	fin = open('in')
except:
	fin = sys.stdin
input = fin.readline

def mergeSort(arr, n):
	temp_arr = [0] * n
	return _mergeSort(arr, temp_arr, 0, n - 1)

def _mergeSort(arr, temp_arr, left, right):
	inv_count = 0
	if left < right:
		mid = (left + right) // 2
		inv_count += _mergeSort(arr, temp_arr, left, mid)
		inv_count += _mergeSort(arr, temp_arr, mid + 1, right)
		inv_count += merge(arr, temp_arr, left, mid, right)
	return inv_count

def merge(arr, temp_arr, left, mid, right):
	i = left
	j = mid + 1
	k = left
	inv_count = 0
	while i <= mid and j <= right:
		if arr[i] <= arr[j]:
			temp_arr[k] = arr[i]
			k += 1
			i += 1
		else:
			temp_arr[k] = arr[j]
			inv_count += mid - i + 1
			k += 1
			j += 1
	while i <= mid:
		temp_arr[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp_arr[k] = arr[j]
		k += 1
		j += 1
	for loop_var in range(left, right + 1):
		arr[loop_var] = temp_arr[loop_var]
	return inv_count
for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	if mergeSort(r, n) * 2 + 2 > n * (n - 1):
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = n * (n - 1) // 2 - 1
	mini = min(l)
	maxi = max(l)
	if mini == maxi:
		print('YES')
	else:
		m = sorted(l)
		if m == list(reversed(l)) and len(set(l)) == n:
			print('NO')
		else:
			print('YES')


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

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, modulus=1):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
		res %= modulus
	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)]
	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(1000000.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 float_array():
	return list(map(float, 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()
	x = len(set(a))
	if x == n and a == sorted(a, reverse=1):
		print('NO')
	else:
		print('YES')


def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def _mergesort(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = _mergesort(arr, temp, left, mid)
		inv_count += _mergesort(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def count(arr, n):
	temp = [0 for i in range(n)]
	return _mergesort(arr, temp, 0, n - 1)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	swap = count(a, n)
	minn = n * (n - 1) // 2 - 1
	if swap <= minn:
		print('YES')
	else:
		print('NO')


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
sys.setrecursionlimit(100000000)
ii = lambda : int(input())
si = lambda : input()
jn = lambda x, l: x.join(map(str, l))
sl = lambda : list(map(str, input().strip()))
mi = lambda : map(int, input().split())
mif = lambda : map(float, input().split())
lii = lambda : list(map(int, input().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))
mod = 1000000007
for _ in range(ii()):
	n = ii()
	arr = lii()
	s = n * (n - 1) // 2
	s -= 1
	a = sorted(arr, reverse=True)
	if a == arr and n == len(set(arr)):
		print('NO')
	else:
		print('YES')


import sys
sys.setrecursionlimit(10 ** 5)
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]

def ok():
	for i in range(n - 1):
		if bb[i] == bb[i + 1]:
			return True
	if aa == bb:
		return False
	return True
for _ in range(II()):
	n = II()
	aa = LI()
	bb = sorted(aa, reverse=True)
	if ok():
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict, Counter
from os import path
import bisect as bi
import heapq
mod = 10 ** 9 + 7

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 inp():
		return int(input())

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

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

	def minp():
		return map(int, stdin.readline().split())
for _ in range(inp()):
	n = inp()
	a = list(minp())
	flag = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			flag = True
	if flag:
		yes()
	else:
		no()


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 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 = mpos(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj
import sys
import threading
from math import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = 0
	for i in range(n - 1):
		if a[i + 1] >= a[i]:
			f = 1
			break
	if f:
		print('YES')
	else:
		print('NO')


def count_inversions(xs):
	n = len(xs)
	cnt = 0
	if n <= 1:
		return (xs, cnt)
	(ls, l_cnt) = count_inversions(xs[:n // 2])
	(rs, r_cnt) = count_inversions(xs[n // 2:])
	ls = ls[::-1]
	rs = rs[::-1]
	result = []
	while ls or rs:
		if not ls:
			result.extend(rs[::-1])
			break
		if not rs:
			result.extend(ls[::-1])
			break
		if ls[-1] <= rs[-1]:
			result.append(ls.pop())
		else:
			result.append(rs.pop())
			cnt += len(ls)
	return (result, cnt + l_cnt + r_cnt)
t = int(input())
for _ in range(t):
	n = int(input())
	xs = [int(x) for x in input().split()]
	inv = count_inversions(xs)[1]
	if inv > n * (n - 1) / 2 - 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = sorted(a, reverse=True)
	c = Counter(a)
	if c.most_common(1)[0][1] != 1 or any((i != j for (i, j) in zip(a, b))):
		print('YES')
	else:
		print('NO')


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
for _ in range(ni()):
	n = ni()
	a = nl()
	f = 0
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			f = 1
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
from queue import deque

def arrinp():
	return [*map(int, input().split(' '))]

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

def intinp():
	return int(input())

def solution():
	n = intinp()
	a = arrinp()
	count = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			count += 1
	if count == n - 1:
		print('NO')
	else:
		print('YES')
testcases = 1
testcases = int(input())
for _ in range(testcases):
	solution()


for _ in range(int(input())):
	z = int(input())
	v = list(map(int, input().split()))
	if sorted(v, reverse=True) == v and len(set(v)) == z:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	x = sorted(set(arr))
	x = list(reversed(x))
	if arr == x and len(arr) == len(x):
		print('NO')
	else:
		print('YES')


def ordertest(A):
	for i in range(len(A) - 1):
		if A[i] <= A[i + 1]:
			return False
	return True
t = int(input())
while t > 0:
	n = int(input())
	arr = [int(i) for i in input().split()]
	if ordertest(arr):
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
z = 0
while z < t:
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	valid = 1
	maximum = a[0]
	index = 1
	while index < n:
		if a[index] < a[index - 1]:
			maximum = a[index - 1]
		else:
			print('YES')
			valid = 0
			break
		index += 1
	if valid:
		print('NO')
	z += 1


from functools import cmp_to_key
from collections import deque
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
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')
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))

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()

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

def ii():
	return int(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

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

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

class UnionFind:

	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
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

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

	def __len__(self):
		return self.num_sets

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)

def custom_sort(lista):

	def cmp(x, y):
		if x + y > y + x:
			return 1
		else:
			return -1
	return sorted(lista, key=cmp_to_key(cmp))
MOD = 10 ** 9 + 7
maxN = 10 ** 5
FACT = [0] * maxN

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

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

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def coeffBinom(n, k):
	if n < k:
		return 0
	return divide(FACT[n], multiply(FACT[k], FACT[n - k]))

def primes(N):
	smallest_prime = [1] * (N + 1)
	prime = []
	smallest_prime[0] = 0
	smallest_prime[1] = 0
	for i in range(2, N + 1):
		if smallest_prime[i] == 1:
			prime.append(i)
			smallest_prime[i] = i
		j = 0
		while j < len(prime) and i * prime[j] <= N:
			smallest_prime[i * prime[j]] = min(prime[j], smallest_prime[i])
			j += 1
	return (prime, smallest_prime)

def gcd(a, b):
	a = abs(a)
	b = abs(b)
	(s, t, r) = (0, 1, b)
	(old_s, old_t, old_r) = (1, 0, a)
	while r != 0:
		quotient = old_r // r
		(old_r, r) = (r, old_r - quotient * r)
		(old_s, s) = (s, old_s - quotient * s)
		(old_t, t) = (t, old_t - quotient * t)
	return (old_r, old_s, old_t)

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def create_edges(m, unweighted=0):
	edges = list()
	if unweighted:
		for i in range(m):
			edges.append(li(lag=-1))
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			edges.append([w, x, y])
	return edges

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def connected(graph, n):
	v = dfs(graph, n, 0)
	for el in v:
		if el == -1:
			return False
	return True

def topological(graph, n):
	indegree = [0] * n
	for el in range(n):
		for child in graph[el]:
			indegree[child] += 1
	s = deque()
	for el in range(n):
		if indegree[el] == 0:
			s.append(el)
	order = []
	while s:
		el = s.popleft()
		order.append(el)
		for child in graph[el]:
			indegree[child] -= 1
			if indegree[child] == 0:
				s.append(child)
	if n == len(order):
		return (False, order)
	else:
		return (True, [])

def bipartite(graph, n):
	color = [-1] * n
	color[0] = 0
	s = [0]
	while s:
		el = s.pop()
		for child in graph[el]:
			if color[child] == color[el]:
				return False
			if color[child] == -1:
				s.append(child)
			color[child] = 1 - color[el]
	return True

def dijkstra(graph, n, A):
	dist = [float('inf') for i in range(n)]
	prev = [-1 for i in range(n)]
	dist[A] = 0
	pq = []
	heappush(pq, [0, A])
	while pq:
		[d_v, v] = heappop(pq)
		if d_v != dist[v]:
			continue
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
				prev[to] = v
				heappush(pq, [dist[to], to])
	return (dist, prev)

def dijkstra_0_1(graph, n, A):
	dist = [float('inf') for i in range(n)]
	dist[A] = 0
	p = deque()
	p.append(A)
	while p:
		v = p.popleft()
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
			if w == 1:
				q.append(to)
			else:
				q.appendleft(to)
	return dist

def floyd_warshall(graph, n):
	dist = [[float('inf') for _ in range(n)] for _ in range(n)]
	for i in range(n):
		dist[i][i] = 0
		for (child, d) in graph[i]:
			dist[i][child] = d
			dist[child][i] = d
	for k in range(n):
		for i in range(n):
			for j in range(j):
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
	return dist

def minimum_spanning_tree(edges, n):
	edges = sorted(edges)
	union_find = UnionFind(n)
	used_edges = list()
	for (w, x, y) in edges:
		if union_find.find(x) != union_find.find(y):
			union_find.merge(x, y)
			used_edges.append([w, x, y])
	return used_edges

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path

def finding_ancestors(parent, queries, n):
	steps = int(ceil(log(n, 2)))
	ancestors = [[-1 for i in range(n)] for j in range(steps)]
	ancestors[0] = parent
	for i in range(1, steps):
		for node in range(n):
			if ancestors[i - 1][node] != -1:
				ancestors[i][node] = ancestors[i - 1][ancestors[i - 1][node]]
	result = []
	for (node, k) in queries:
		ans = node
		if k >= n:
			ans = -1
		i = 0
		while k > 0 and ans != -1:
			if k % 2:
				ans = ancestors[i][ans]
			k = k // 2
			i += 1
		result.append(ans)
	return result

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def nearest_from_the_left_smaller_elements(arr):
	n = len(arr)
	res = [-1] * n
	s = []
	for (i, el) in enumerate(arr):
		while s and s[-1] >= el:
			s.pop()
		if s:
			res[i] = s[-1]
		s.append(el)
	return res

def sliding_window_minimum(arr, k):
	res = []
	q = deque()
	for (i, el) in enumerate(arr):
		while q and arr[q[-1]] >= el:
			q.pop()
		q.append(i)
		while q and q[0] <= i - k:
			q.popleft()
		if i >= k - 1:
			res.append(arr[q[0]])
	return res
for test in range(ii()):
	n = ii()
	a = li()
	flag = True
	for i in range(1, n):
		if a[i - 1] <= a[i]:
			flag = False
	if flag == True:
		print('NO')
	else:
		print('YES')


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


n = int(input())
for i in range(n):
	f = int(input())
	l = list(map(int, input().split()))[:f]
	d = sorted(l, reverse=True)
	s = sorted(l)
	if d == s and s == l:
		print('YES')
	elif d == l and len(set(l)) == f:
		print('NO')
	else:
		print('YES')


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
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('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = 998244353
INF = float('inf')
for t in range(int(data())):
	n = int(data())
	a = mdata()
	a1 = sorted(a)
	if a1 == a[::-1] and len(set(a)) == n:
		out('NO')
	else:
		out('YES')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	res = 'NO'
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			res = 'YES'
			break
	print(res)


t = int(input())
a = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	i = 0
	flag = 'NO'
	for r in range(1, n):
		if a[r] >= a[r - 1]:
			flag = 'YES'
			break
	print(flag)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	m = sorted(list(set(x)), reverse=True)
	if m == x:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)[::-1]
	ok = True
	for i in range(len(a) - 1):
		if a[i] <= a[i + 1]:
			ok = False
			break
	if not ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = sorted(arr)
	brr.reverse()
	if len(set(arr)) == n:
		if arr == brr:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


import math
from collections import defaultdict
import functools as f
from itertools import permutations as p
t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	val = n * (n - 1) / 2 - 1
	val = int(val)
	b = sorted(a)
	co = 0
	for i in range(n - 1):
		if a[i + 1] - a[i] < 0:
			k = b.index(a[i])
			co += k
	if co > val:
		print('NO')
	else:
		print('YES')


forCount = int(input())
for i in range(forCount):
	c = 0
	boxCount = int(input())
	if boxCount == 1:
		print('YES')
		continue
	boxVolumes = input().split()
	for j in range(len(boxVolumes) - 1, -1, -1):
		if j == 0:
			c += 1
			break
		if int(boxVolumes[j]) < int(boxVolumes[j - 1]):
			c += 1
		else:
			print('YES')
			break
	if c == len(boxVolumes):
		print('NO')


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	if lst == sorted(lst):
		print('YES')
	elif lst == sorted(lst)[::-1] and len(lst) == len(set(lst)):
		print('NO')
	else:
		print('YES')


from bisect import *
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = 0
	for i in range(n - 1):
		if l[i + 1] >= l[i]:
			f = 1
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = I()
	an = 'YES'
	p = sorted(l, reverse=True)
	ans = len(set(l))
	if n > 1 and (ans == n and p == l):
		an = 'NO'
	print(an)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	if a == sorted(a, reverse=True) and len(set(a)) == n:
		print('NO')
	else:
		print('YES')


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')
import math
from collections import Counter, defaultdict, deque

def int1():
	return int(input())

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

def list1():
	return list(map(int, input().split()))
mod = pow(10, 9) + 7

def solve():
	n = int1()
	l1 = list1()
	s = len(set(l1))
	if s != n:
		print('YES')
		return
	l2 = l1.copy()
	l2.sort(reverse=True)
	if l1 == l2:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	solve()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = sorted(a, reverse=True)
	if a != b:
		print('YES')
	else:
		f = 0
		d = Counter(b)
		for x in d:
			if d[x] > 1:
				f = 1
				break
		if f == 0:
			print('NO')
		else:
			print('YES')


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	if len(l) == len(s) and sorted(l, reverse=True) == l:
		print('NO')
	else:
		print('YES')


from collections import Counter
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	b = Counter(a)
	if len(b) == n:
		f = 0
		a1 = sorted(a, reverse=True)
		for i in range(n):
			if a[i] != a1[i]:
				f = 1
				print('YES')
				break
		if f == 0:
			print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for test in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	mozme = False
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			mozme = True
			break
	print('YES' if mozme else 'NO')


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


def check(a):
	for i in range(len(a) - 1):
		if a[i + 1] - a[i] >= 0:
			return 'YES'
	return 'NO'
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(check(a))
	t = t - 1


from collections import defaultdict, Counter, deque
t = int(input())
arr = []
for _ in range(t):
	k = input()
	arr.append(list(map(int, input().split())))
for lis in arr:
	c = Counter(lis)
	if len(c) == len(lis) and lis[::-1] == sorted(lis):
		print('NO')
	else:
		print('YES')


t = int(input())
for e in range(t):
	n = int(input())
	v = [*map(int, input().split())]
	rev = True
	for i in range(1, n):
		if v[i - 1] <= v[i]:
			rev = False
			break
	if rev:
		print('NO')
	else:
		print('YES')


def li():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	n = int(input())
	a = li()
	if len(set(a)) == n:
		if sorted(a, reverse=True) == a:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


def fn1(lis, arr):
	if lis == arr:
		print('NO')
	else:
		print('YES')
t = int(input())
for tc in range(t):
	m = int(input())
	lis = list(map(int, input().split()))
	arr = list(reversed(sorted(lis)))
	if lis == list(sorted(lis)) or len(set(lis)) < len(lis):
		print('YES')
	else:
		fn1(lis, arr)


cases = int(input())
for _ in range(cases):
	n = int(input())
	ds = list(map(int, input().split()))
	found = False
	for i in range(n - 1, 0, -1):
		if ds[i] >= ds[i - 1]:
			found = True
			break
	if found:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import Counter
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = li()
	f = 0
	for i in range(1, n):
		if l[i] >= l[i - 1]:
			f = 1
			break
	if f == 0:
		pr('NO')
	else:
		pr('YES')
for _ in range(inp()):
	solve()


def fuckIt(arr, n):
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			return True
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if fuckIt(arr, n):
		print('YES')
	else:
		print('NO')
	t = t - 1


def cubesSorting():
	for t in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		succ = 0
		for i in range(n - 1):
			if a[i] <= a[i + 1]:
				print('YES')
				succ = 1
				break
		if succ == 0:
			print('NO')
cubesSorting()


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


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)[::-1]
	if len(set(a)) != n or a != b:
		print('YES')
	else:
		print('NO')


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
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	B = A.copy()
	if len(set(A)) == 1:
		print('YES')
		continue
	B.sort(reverse=True)
	if B == A and len(set(A)) == n:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l = [int(c) for c in input().split()]
	if len(set(l)) != len(l):
		print('YES')
		continue
	t = sorted(l, reverse=True)
	if l == t:
		print('NO')
	else:
		print('YES')


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

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 list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	cnt = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			cnt += 1
	if cnt < n - 1:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	n = int(stdin.readline())
	ar = list(map(int, stdin.readline().split()))
	b = True
	for i in range(n - 1):
		if ar[i] <= ar[i + 1]:
			b = False
			break
	if b:
		res = 'NO'
	else:
		res = 'YES'
	stdout.write(str(res) + '\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	aSortedReversed = sorted(a, reverse=True)
	b = False
	for i in range(n - 1):
		if aSortedReversed[i] == aSortedReversed[i + 1]:
			b = True
			break
	if b or a != aSortedReversed:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	flag = False
	for i in range(1, n):
		if arr[i - 1] <= arr[i]:
			flag = True
			break
	if flag:
		print('YES')
	else:
		print('NO')


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()
	w = dict()
	for i in range(n):
		if q[i] in w:
			w[q[i]] += 1
		else:
			w[q[i]] = 1
		if w[q[i]] >= 2 or (i and q[i] > q[i - 1]):
			print('YES')
			return 0
	print('NO')
for i in range(iinput()):
	main()


for x in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 1
	can = False
	while i < n:
		if a[i] >= a[i - 1]:
			can = True
			break
		i += 1
	if can:
		print('YES')
	else:
		print('NO')


import sys

def is_decreasing(a):
	for i in range(len(a) - 1):
		if a[i + 1] >= a[i]:
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().strip().split(' ')))
	print('NO' if is_decreasing(A) else 'YES')


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
import math
for _ in range(vary(1)):
	n = vary(1)
	num = array_int()
	if n == 1:
		print('YES')
		continue
	for i in range(n - 1):
		if num[i] <= num[i + 1]:
			print('YES')
			break
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	m = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			m = 1
			break
	if m == 1:
		print('Yes')
	else:
		print('No')


for i in ' ' * int(input()):
	n = int(input())
	L = list(map(int, input().split()))
	state = False
	for j in range(n - 1):
		if L[j] <= L[j + 1]:
			state = True
	print(['NO', 'YES'][state])


for _ in range(int(input())):
	n = int(input())
	t = tuple(map(int, input().split()))
	l = list(t)
	l.sort(reverse=True)
	flag = 0
	for i in range(n):
		if l[i] != t[i]:
			flag = 1
			break
	if flag == 0 and len(set(l)) == len(l):
		print('NO')
	else:
		print('YES')


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

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

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

def invr():
	return map(int, input().split())
n = inp()
for _ in range(n):
	m = inp()
	l = inlt()
	prev = l[0] + 1
	flag = 1
	for x in l:
		if x >= prev:
			print('YES')
			flag = 0
			break
		prev = x
	if flag:
		print('NO')


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		a = list(_read_ints())
		if not _is_strictly_reversed(a):
			output = 'YES'
		else:
			output = 'NO'
		print(output)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split(' '))

def _is_strictly_reversed(seq):
	for i in range(len(seq) - 1):
		if not seq[i] > seq[i + 1]:
			return False
	return True
main()


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


from sys import stdin

def readline():
	return stdin.readline()

def solve(n, a):
	s = set(a)
	return 'NO' if len(s) == len(a) and list(reversed(sorted(a))) == a else 'YES'
tests = int(readline())
for t in range(0, tests):
	n = int(readline())
	a = list(map(int, readline().rstrip('\n').split(' ')))
	print(solve(n, a))


import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	a = Read.list_int()
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			print('YES')
			return
	print('NO')
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


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


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = [i for i in A]
	B.sort(reverse=True)
	if B == A and len(list(set(B))) == len(B):
		print('NO')
	else:
		print('YES')


def check(a, m):
	for i in range(m - 1):
		if a[i] <= a[i + 1]:
			return 'YES'
	return 'NO'
n = int(input())
for i in range(n):
	m = int(input())
	lis = list(map(int, input().split()))
	print(check(lis, m))


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

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

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

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

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = inar()
		take1 = arr.copy()
		take2 = arr.copy()
		take2 = set(take2)
		take1.sort(reverse=True)
		if take1 == arr and len(take2) == len(arr):
			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()


def ask(a):
	for i in range(1, len(a)):
		if a[i] >= a[i - 1]:
			return True
	return False
for i in range(int(input())):
	n = input()
	a = list(map(int, input().split()))
	if ask(a):
		print('YES')
	else:
		print('NO')


def canSort(n, a):
	allowed = n * (n - 1) / 2 - 1
	needs = 0

	def merge(arr, l, mid, r):
		nonlocal needs
		(i, j) = (l, mid)
		marr = []
		while i < mid and j < r:
			if arr[i] <= arr[j]:
				marr.append(arr[i])
				i += 1
			else:
				needs += mid - i
				marr.append(arr[j])
				j += 1
		while i < mid:
			marr.append(arr[i])
			i += 1
		while j < r:
			marr.append(arr[j])
			j += 1
		arr[l:r] = marr
		return

	def mergesort(arr, l, r):
		if r == l + 1:
			return arr
		mid = (l + r) // 2
		mergesort(arr, l, mid)
		mergesort(arr, mid, r)
		merge(arr, l, mid, r)
		return
	mergesort(a, 0, n)
	if needs > allowed:
		return 'NO'
	else:
		return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(canSort(n, a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a, reverse=True)
	c = sorted(a)
	found = 0
	dict1 = dict()
	for items in a:
		if items in dict1:
			found = 1
			break
		else:
			dict1[items] = 1
	if a == c or found == 1 or a != b:
		print('YES')
	else:
		print('NO')


t = int(input())
from collections import Counter
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	z = list(reversed(sorted(arr)))
	c = Counter(arr)
	if z[0] == z[-1]:
		print('YES')
		continue
	if z != arr:
		print('YES')
		continue
	else:
		if max(c.values()) >= 2:
			print('YES')
			continue
		print('NO')


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18

def merge(arr, temp, left, mid, right):
	inv_count = 0
	i = left
	j = mid
	k = left
	while i <= mid - 1 and j <= right:
		if arr[i] <= arr[j]:
			temp[k] = arr[i]
			k += 1
			i += 1
		else:
			temp[k] = arr[j]
			k += 1
			j += 1
			inv_count = inv_count + (mid - i)
	while i <= mid - 1:
		temp[k] = arr[i]
		k += 1
		i += 1
	while j <= right:
		temp[k] = arr[j]
		k += 1
		j += 1
	for i in range(left, right + 1, 1):
		arr[i] = temp[i]
	return inv_count

def merges(arr, temp, left, right):
	inv_count = 0
	if right > left:
		mid = int((right + left) / 2)
		inv_count = merges(arr, temp, left, mid)
		inv_count += merges(arr, temp, mid + 1, right)
		inv_count += merge(arr, temp, left, mid + 1, right)
	return inv_count

def swaps(arr, n):
	temp = [0 for i in range(n)]
	return merges(arr, temp, 0, n - 1)
for _ in range(inn()):
	n = inn()
	a = arr()
	ans = 'YES'
	b = a[:]
	if a == sorted(a):
		print(ans)
		continue
	res = swaps(a, n)
	val = n * (n - 1) // 2 - 1
	if res > val:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	check = 0
	input()
	a = list(map(int, input().split()))
	for i in range(len(a) - 1):
		if a[i + 1] >= a[i]:
			check = 1
			break
	if check == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
X = []
for i in range(t):
	n = int(input())
	m = [int(i) for i in input().split()]
	x = 0
	for i in range(1, n):
		if m[i - 1] > m[i]:
			x += 1
	if x == n - 1:
		X.append('NO')
	else:
		X.append('YES')
for i in range(t):
	print(X[i])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = False
	larg = arr[0]
	for i in range(1, n):
		if arr[i] >= larg:
			flag = True
			break
		else:
			larg = arr[i]
	if flag:
		print('YES')
	else:
		print('NO')


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


def solution(l):
	for j in range(1, n):
		if l[j] < l[j - 1]:
			continue
		else:
			print('YES')
			return
	print('NO')
for i in range(int(input())):
	n = int(input())
	c = 0
	l = list(map(int, input().split()))
	solution(l)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	sor = arr[:]
	unsor = arr[:]
	sor.sort()
	unsor.sort(reverse=True)
	flag = 'NO'
	for i in range(1, n):
		if unsor[i] == unsor[i - 1]:
			flag = 'YES'
			break
	if flag == 'YES':
		print(flag)
	elif arr == unsor:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	exp = input()
	exp = exp.split()
	exp2 = []
	count = 0
	for j in exp:
		exp2.append(int(j))
	for k in range(len(exp2) - 1):
		if exp2[k] <= exp2[k + 1]:
			print('YES')
			break
	else:
		print('NO')


from sys import stdin, stdout, setrecursionlimit
import threading

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()]
			b = a.copy()
			b.sort(reverse=True)
			s = set()
			for j in range(n):
				s.add(a[j])
			if len(s) < n:
				ans.append('YES')
				continue
			ret = 0
			for j in range(n):
				if a[j] != b[j]:
					ret = 1
					break
			if ret:
				ans.append('YES')
			else:
				ans.append('NO')
		W('\n'.join(ans))
		return 0

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


for _ in range(0, int(input())):
	n = int(input())
	a = n * (n - 1) // 2 - 1
	x = list(map(int, input().split()))
	y = sorted(x)
	z = []
	for i in range(n - 1, -1, -1):
		z.append(y[i])
	if z == x and len(set(x)) == n:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	t1 = dict()
	for x in arr:
		if x in t1.keys():
			t1[x] += 1
		else:
			t1[x] = 1
	if len(t1) != n:
		print('YES')
		continue
	temp = arr.copy()
	temp.sort(reverse=True)
	if arr == temp:
		print('NO')
	else:
		print('YES')


def count_inversion(lst):
	return merge_count_inversion(lst)[1]

def merge_count_inversion(lst):
	if len(lst) <= 1:
		return (lst, 0)
	middle = int(len(lst) / 2)
	(left, a) = merge_count_inversion(lst[:middle])
	(right, b) = merge_count_inversion(lst[middle:])
	(result, c) = merge_count_split_inversion(left, right)
	return (result, a + b + c)

def merge_count_split_inversion(left, right):
	result = []
	count = 0
	(i, j) = (0, 0)
	left_len = len(left)
	while i < left_len and j < len(right):
		if left[i] <= right[j]:
			result.append(left[i])
			i += 1
		else:
			result.append(right[j])
			count += left_len - i
			j += 1
	result += left[i:]
	result += right[j:]
	return (result, count)
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	t = n * (n - 1) // 2 - 1
	cnt = count_inversion(x)
	if cnt > t:
		print('NO')
	else:
		print('YES')


t = int(input())
for case in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr2 = list(reversed(sorted(arr)))
	distinct = True
	for i in range(1, n):
		if arr2[i] == arr2[i - 1]:
			distinct = False
	if arr == arr2 and distinct:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	inv = n * (n - 1) // 2 - 1
	flag = False
	for i in range(1, n):
		if l[i - 1] <= l[i]:
			flag = True
	print('YES' if flag else 'NO')


import sys, collections, math

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

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

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	n = int(input())
	arr = get_array()
	cnt = 0
	for i in range(n - 1):
		if arr[i + 1] >= arr[i]:
			continue
		for j in range(n - 1, i, -1):
			if arr[i] > arr[j]:
				cnt += j - i
				break
	if cnt > n * (n - 1) // 2 - 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	badc = 0
	for i in range(1, n):
		if s[i] < s[i - 1]:
			badc += 1
	if n >= 3:
		if badc == n - 1:
			print('NO')
		else:
			print('YES')
	elif s[0] <= s[1]:
		print('YES')
	else:
		print('NO')


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()
	flag = 1
	for i in range(n - 1):
		if x[i] > x[i + 1]:
			flag = 0
		else:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


from os import path
import sys
from heapq import heappush, heappop
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().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
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')

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = a[:]
		b.sort(reverse=True)
		n1 = len(set(a))
		if b != a or n1 != n:
			print('YES')
		else:
			print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


from collections import defaultdict
import sys
import math

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	if len(set(a)) == n:
		if sorted(a, reverse=True) == a:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


from typing import List

def is_sorted(a: List[int]) -> bool:
	return a == sorted(a)

def problem_a(n: int, a: List[int]) -> str:
	for i in range(n - 1, 0, -1):
		if a[i] >= a[i - 1]:
			return 'YES'
	return 'NO'
tests = int(input())
for t in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	print(problem_a(n, a))


from collections import defaultdict, deque
import heapq as hq
from random import randint as rd
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	asc = list(sorted(arr))
	desc = list(sorted(arr, reverse=True))
	unique = set(arr)
	if desc == arr and asc != arr and (len(unique) == len(desc)):
		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()))
	B = []
	for i in A:
		B.append(i)
	A.sort(reverse=True)
	fg = 0
	for i in range(N):
		if B[i] != A[i]:
			fg = 1
			break
	for i in range(1, N):
		if B[i] == B[i - 1]:
			fg = 1
			break
	if fg == 0:
		print('NO')
	else:
		print('YES')


def merge(ar, tp, l, m, h):
	c = 0
	i = l
	j = m
	k = l
	while i <= m - 1 and j <= h:
		if ar[i] <= ar[j]:
			tp[k] = ar[i]
			k += 1
			i += 1
		else:
			tp[k] = ar[j]
			k += 1
			j += 1
			c += m - i
	while i <= m - 1:
		tp[k] = ar[i]
		k += 1
		i += 1
	while j <= h:
		tp[k] = ar[j]
		k += 1
		j += 1
	ar[l:h + 1] = tp[l:h + 1]
	return c

def mergeSort(ar, tp, l, h):
	c = 0
	if l < h:
		m = (l + h) // 2
		c += mergeSort(ar, tp, l, m)
		c += mergeSort(ar, tp, m + 1, h)
		c += merge(ar, tp, l, m + 1, h)
	return c

def noOfSwaps(ar, n):
	tp = [0] * n
	return mergeSort(ar, tp, 0, n - 1)
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	s = noOfSwaps(ar, n)
	ans = n * (n - 1) // 2 - 1
	if s <= ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if len(set(a)) != n:
		print('YES')
	else:
		check = 1
		for i in range(1, n):
			if a[i] > a[i - 1]:
				check = 0
				break
		if check == 1:
			print('NO')
		else:
			print('YES')


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()
		f = True if len(a) != len(set(a)) else False
		if f or a[::-1] != sorted(a):
			print('YES')
		else:
			print('NO')
solve()


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	M = n * (n - 1) // 2 - 1
	ans = 'NO'
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			ans = 'YES'
			break
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	res = 'NO'
	i = 1
	while i <= n - 1:
		if l[i] >= l[i - 1]:
			res = 'YES'
		i += 1
	print(res)


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