Chef received a new sequence $A_1, A_2, \ldots, A_N$. He does not like arbitrarily ordered sequences, so he wants to permute the elements of $A$ in such a way that it would satisfy the following condition: there is an integer $p$ ($1 \le p \le N$) such that the first $p$ elements of the new (permuted) sequence are strictly increasing and the last $N-p+1$ elements are strictly decreasing.
Help Chef and find a permutation of the given sequence which satisfies this condition or determine that no such permutation exists. If there are multiple solutions, you may find any one.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case:
- If there is no permutation of $A$ that satisfies the given condition, print a single line containing the string "NO" (without quotes).
- Otherwise, print two lines.
- The first of these lines should contain the string "YES" (without quotes).
- The second line should contain $N$ space-separated integers ― the elements of your permuted sequence.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 10^5$
- $1 \le A_i \le 2 \cdot 10^5$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Subtasks-----
Subtask #1 (50 points):
- $N \le 10^3$
- $A_i \le 2 \cdot 10^3$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^4$
Subtask #2 (50 points): original constraints

-----Example Input-----
5
4
1 3 2 4
4
1 3 2 4
6
1 10 10 10 20 15
5
1 1 2 2 3
4
1 2 3 3

-----Example Output-----
YES
1 2 3 4
YES
4 3 2 1
NO
YES
1 2 3 2 1
NO

Source: codechef | Difficulty: MEDIUM
Tags: Constructive algorithms

Implementation

Ad-hoc


Solutions:
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set()
	c = []
	for i in a:
		if i in b:
			c.append(i)
		else:
			b.add(i)
	b = list(b)
	b.sort()
	c.sort(reverse=True)
	arr = b[:] + c[:]
	flag = 0
	for i in range(len(b) - 1, n - 1):
		if arr[i] == arr[i + 1]:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
		print(*arr)


n = int(input())
for p in range(n):
	xx = int(input())
	a = list(map(int, input().split()))
	b = []
	flag = 0
	aa = a.copy()
	aa.sort()
	i = 0
	while i < xx - 2:
		if aa[len(aa) - 1] == aa[len(aa) - 2] or aa[i] == aa[i + 2]:
			flag = 1
			break
		elif aa[i] == aa[i + 1]:
			b.append(aa[i + 1])
			aa.pop(i + 1)
		xx = len(aa)
		i += 1
	b.sort(reverse=True)
	if flag == 0:
		print('YES')
		print(*aa, end=' ')
		print(*b)
	else:
		print('NO')


try:
	t = int(input())
	while t > 0:
		t = t - 1
		n = int(input())
		arr = [int(h) for h in input().split()]
		a = set()
		b = list()
		for i in range(n):
			if arr[i] not in a:
				a.add(arr[i])
			else:
				b.append(arr[i])
		a = list(a)
		a.sort()
		b.sort(reverse=True)
		arr = a[:] + b[:]
		flag = 0
		for i in range(len(a) - 1, n - 1):
			if arr[i] == arr[i + 1]:
				flag = 1
				print('NO')
				break
		if flag == 0:
			print('YES')
			print(*arr)
except:
	pass


from sys import stdin

def input():
	return stdin.readline()
for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	dict1 = {}
	max1 = 0
	nk = 0
	lst1 = []
	lst2 = []
	for i in lst:
		if max1 < i:
			max1 = i
		if i in dict1:
			dict1[i] += 1
			lst2.append(i)
			if dict1[i] > 2:
				nk = 1
				break
		else:
			dict1[i] = 1
			lst1.append(i)
	if dict1[max1] != 1 or nk == 1:
		print('NO')
	else:
		print('YES')
		lst1.sort()
		lst2.sort(reverse=True)
		for i in lst1:
			print(i, end=' ')
		for i in lst2:
			print(i, end=' ')
		print()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = set()
	c = []
	for i in a:
		if i not in b:
			b.add(i)
		else:
			c.append(i)
	b = list(b)
	b.sort()
	c.sort(reverse=True)
	e = b + c
	k = 0
	for i in range(len(e) - 1):
		if e[i] == e[i + 1]:
			k = 1
			print('NO')
			break
	if k == 0:
		print('YES')
		print(*e)


def solve(n, lst):
	d = dict()
	p1 = []
	p2 = []
	for i in lst:
		if i in d.keys():
			d[i] += 1
			p2.append(i)
			if d[i] > 2:
				return -1
		else:
			p1.append(i)
			d[i] = 1
	if d[max(p1)] > 1:
		return -1
	p1.sort()
	p2.sort()
	p2.reverse()
	return p1 + p2
t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split(' ')))
	res = solve(n, lst)
	if res == -1:
		print('NO')
	else:
		print('YES' + '\n' + ' '.join(map(str, res)))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	arr1 = list(set(arr))
	arr1.sort()
	arr2 = []
	for i in range(n - 1):
		if arr[i] == arr[i + 1]:
			arr2.append(arr[i])
	arr2 = list(set(arr2))
	arr2.sort()
	arr2.reverse()
	ans = arr1 + arr2
	if len(arr) != len(ans) or (len(arr) > 1 and arr[-1] == arr[-2]):
		print('NO')
	else:
		print('YES')
		print(*ans)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	a = set()
	b = []
	for j in range(n):
		if arr[j] not in a:
			a.add(arr[j])
		else:
			b.append(arr[j])
	a = list(a)
	a.sort()
	b.sort(reverse=True)
	resul = a[:] + b[:]
	for j in range(len(resul) - 1):
		if resul[j] == resul[j + 1]:
			print('NO')
			break
	else:
		print('YES')
		print(*resul)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	d = {}
	c = 0
	for i in lst:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in d:
		if d[i] > 2:
			c = -1
			break
	if d[max(lst)] == 2:
		c = -1
	if c == 0:
		lst = sorted(lst)
		l1 = [str(lst[i]) for i in range(0, len(lst), 2)]
		l2 = [str(lst[i]) for i in range(1, len(lst), 2)]
		f = l1 + l2[::-1]
		print('YES')
		print(' '.join(f))
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	flag = True
	d = {}
	for i in arr:
		if d.get(i) is None:
			d[i] = 1
		else:
			d[i] += 1
			if d[i] > 2:
				flag = False
				break
	dec = []
	ans = [arr[0]]
	if flag and d[arr[-1]] == 1:
		for i in range(1, n):
			if arr[i] == arr[i - 1]:
				dec.append(arr[i])
			else:
				ans.append(arr[i])
		for i in range(len(dec) - 1, -1, -1):
			ans.append(dec[i])
		print('YES')
		print(*ans)
	else:
		print('NO')


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr = iia()
	(a, b) = (set(), set())
	for i in arr:
		if i not in a:
			a.add(i)
		elif i not in b:
			b.add(i)
		else:
			print('NO')
			break
	else:
		a = sorted(list(a))
		b = sorted(list(b), reverse=True)
		if len(a) and len(b) and (a[-1] == b[0]):
			print('NO')
		else:
			print('YES')
			arr = a + b
			print(*arr)


t = int(input())
for _ in range(t):
	n = int(input())
	d = dict()
	l = list(map(int, input().split()))
	for i in l:
		d[i] = d.get(i, 0) + 1
	if l.count(max(l)) > 1:
		print('NO')
		continue
	for i in d:
		if d[i] > 2:
			print('NO')
			break
	else:
		f = []
		k = []
		for i in d:
			if d[i] == 2:
				f.append(i)
				k.append(i)
			else:
				f.append(i)
		f.sort()
		k.sort(reverse=True)
		print('YES')
		for i in f:
			print(i, end=' ')
		for i in k:
			print(i, end=' ')
		print()


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	c = Counter(a)
	if c[max(a)] > 1:
		print('NO')
	else:
		for i in c:
			if c[i] > 2:
				print('NO')
				break
		else:
			print('YES')
			s = set(a)
			l = list(s)
			l.sort()
			for i in c:
				if c[i] == 1:
					s.remove(i)
			l.extend(sorted(s, reverse=True))
			for i in l:
				print(i, end=' ')
			print()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = [-1]
	c = [-1]
	prev = nex = 0
	flag = True
	i = 0
	f = False
	while i < n:
		if flag:
			if a[i] == prev:
				flag = False
				if a[i] == nex:
					f = True
					break
				i -= 1
			else:
				b.append(a[i])
				prev = a[i]
		elif a[i] == nex:
			flag = True
			if a[i] == prev:
				f = True
				break
			i -= 1
		else:
			c.append(a[i])
			nex = a[i]
		i += 1
	flag = True
	b.sort()
	c.sort(reverse=True)
	ans = b[1:] + c[:-1]
	for i in range(1, len(ans)):
		if ans[i] == ans[i - 1]:
			f = True
			break
	if f:
		print('NO')
	else:
		print('YES')
		for i in ans:
			print(i, end=' ')
		print()


T = int(input())
for _ in range(T):
	N = int(input())
	L = list(map(int, input().split()))
	L.sort()
	flag = 0
	L1 = []
	L2 = []
	L1.append(L[0])
	for i in range(1, N):
		if L[i] == L[i - 1]:
			L2.append(L[i])
		else:
			L1.append(L[i])
	for i in range(1, len(L2)):
		if L2[i] == L2[i - 1]:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		L2.sort(reverse=True)
		if len(L2) != 0:
			if L1[-1] == L2[0]:
				print('NO')
				flag = 2
		if flag != 2:
			print('YES')
			for i in L1:
				print(i, end=' ')
			for i in L2:
				print(i, end=' ')
			print('')


from collections import Counter
for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	x.sort()
	y = Counter(x)
	u = 0
	for j in y:
		if y[j] > 2:
			u = 1
			break
	if u == 1:
		print('NO')
	else:
		s = list(set(x))
		s.sort()
		am = s.copy()
		bm = []
		for k in y:
			if y[k] > 1:
				bm.append(k)
		bm.sort()
		bm.reverse()
		z = am + bm
		c = 0
		d = 0
		k = 0
		for i in range(len(z) - 1):
			if z[i + 1] > z[i]:
				if k == 1:
					break
				else:
					c += 1
			else:
				k = 1
				if z[i + 1] < z[i]:
					d += 1
				else:
					break
		if d == 0:
			c += 1
		else:
			d = d + 1
		if c + d == n:
			print('YES')
			print(*z)
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	x = max(list1)
	map1 = dict()
	for val in list1:
		if val in map1:
			map1[val] += 1
		else:
			map1[val] = 1
	ans = 1
	for val in map1:
		if val == x:
			if map1[val] > 1:
				ans = 0
				break
		elif map1[val] > 2:
			ans = 0
			break
	if ans:
		print('YES')
		ans1 = sorted(map1)
		ans2 = []
		for val in ans1:
			if map1[val] == 2:
				ans2.append(val)
		ans2.reverse()
		for val in ans1:
			print(val, end=' ')
		for val in ans2:
			print(val, end=' ')
		print()
	else:
		print('NO')


from collections import defaultdict

def find(li, n):
	d = {}
	li.sort()
	for i in range(n):
		if li[i] not in d:
			d[li[i]] = 1
		else:
			d[li[i]] += 1
			if d[li[i]] > 2:
				return 'NO'
	ans = []
	for i in d:
		ans.append(i)
		d[i] -= 1
	for i in range(len(li) - 1, -1, -1):
		if d[li[i]] != 0:
			if ans[-1] == li[i]:
				return 'NO'
			x = d[li[i]]
			while x != 0:
				ans.append(li[i])
				x -= 1
				d[li[i]] -= 1
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	ans = find(li, n)
	if ans != 'NO':
		print('YES')
		for j in ans:
			print(j, end=' ')
		print()
	else:
		print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	f = Counter(a)
	if a.count(max(a)) > 1:
		print('NO')
	else:
		lhs = []
		rhs = []
		foe = 0
		for (i, value) in f.items():
			if value == 1:
				lhs.append(i)
			elif value == 2:
				lhs.append(i)
				rhs.append(i)
			else:
				print('NO')
				foe = 1
				break
		if foe == 1:
			continue
		else:
			lhs.sort()
			rhs.sort(reverse=True)
			print('YES')
			print(*lhs, *rhs)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	has_true = True
	max_a = max(a)
	series1 = []
	series2 = []
	if a.count(max_a) > 1:
		print('NO')
		continue
	i = 0
	a.sort()
	while i < n:
		if a.count(a[i]) > 2:
			has_true = False
			print('NO')
			break
		if a.count(a[i]) == 2:
			series1.append(a[i])
			series2.append(a[i])
			i += 1
		else:
			series1.append(a[i])
		i += 1
	if has_true == True:
		series2 = series2[::-1]
		print('YES')
		print(*series1 + series2)


def debug(*args, **kwargs):
	print(*args, dict(**kwargs))

def printResult(result):
	if isinstance(result, list):
		print(*result)
	else:
		print(result)

def main():
	noOfTests = int(input())
	for i in range(noOfTests):
		result = runATest(i)
		if isinstance(result, tuple):
			for line in result:
				printResult(line)
		else:
			printResult(result)

def runATest(_testIndex):
	count = int(input())
	if count == 0:
		return 'NO'
	aList = [int(x) for x in input().split()]
	aList.sort()
	lastNo = 0
	foundDup = False
	duplicates = []
	for i in aList:
		if i != lastNo:
			lastNo = i
			foundDup = False
		elif foundDup:
			return 'NO'
		else:
			foundDup = True
			duplicates.insert(0, i)
	if foundDup:
		return 'NO'
	if len(duplicates) == 0:
		return ('YES', aList)
	i = count - 1
	j = 0
	dupCount = len(duplicates)
	while i >= 0:
		if aList[i] == duplicates[j]:
			del aList[i]
			i -= 1
			j += 1
			if j == dupCount:
				break
		i -= 1
	aList.extend(duplicates)
	return ('YES', aList)
main()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = []
	c = []
	flag = 0
	i = 0
	if a.count(a[-1]) > 1:
		flag = 1
	while i < n:
		if a.count(a[i]) > 2:
			flag = 1
			break
		elif a.count(a[i]) == 2 and flag != 1:
			b.append(a[i])
			c.append(a[i])
			i += 1
		else:
			b.append(a[i])
		i += 1
	c = c[::-1]
	if flag == 1:
		print('NO')
	else:
		print('YES')
		print(*b + c)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	ans = 'Yes'
	for i in l:
		if i in d:
			d[i] += 1
			if d[i] > 2:
				ans = 'No'
		else:
			d[i] = 1
	if ans == 'No' or d[max(l)] > 1:
		print('NO')
	else:
		print('YES')
		l1 = sorted(d.keys())
		for i in l1[::-1]:
			if d[i] == 2:
				l1.append(i)
		print(*l1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = list(dict.fromkeys(a))
	if a == sorted(b):
		print('YES')
		print(*a)
		continue
	c = max(b)
	if a.count(c) > 1:
		print('NO')
		continue
	l = []
	r = []
	p = 1
	i = 0
	while i < n:
		if i < n - 2:
			if a[i] == a[i + 2]:
				print('NO')
				p = 0
				break
		if i < n - 1:
			if a[i] == a[i + 1]:
				l.append(a[i])
				r.append(a[i])
				i += 2
			else:
				l.append(a[i])
				i += 1
		else:
			l.append(a[i])
			i += 1
	if p:
		print('YES')
		print(*l, end=' ')
		print(*r[::-1])


def sol(arr, n):
	(i, de) = ([], [])
	d = {}
	for ele in arr:
		if ele in d:
			d[ele] += 1
		else:
			d[ele] = 1
		if d[ele] == 1:
			i.append(ele)
		elif d[ele] == 2:
			de.append(ele)
		else:
			return False
	i.sort()
	de.sort(reverse=True)
	if len(de) != 0:
		if i[len(i) - 1] == de[0]:
			return False
		else:
			i.extend(de)
			return i
	else:
		return i
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = sol(arr, n)
	if ans == False:
		print('NO')
	else:
		print('YES')
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = []
	flag = 0
	if a[n - 1] == a[n - 2]:
		print('NO')
		continue
	i = 0
	while i < n - 2:
		if a[i] == a[i + 2]:
			flag = 1
			break
		elif a[i] == a[i + 1]:
			b.append(a.pop(i))
			n = n - 1
		i += 1
	if flag == 0:
		b.sort(reverse=True)
		print('YES')
		print(*a + b)
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	li = [int(x) for x in input().split()]
	l = [0 for i in range(max(li) + 1)]
	for i in range(len(li)):
		l[li[i]] = l[li[i]] + 1
	if max(l) >= 3:
		print('NO')
	elif l[max(li)] >= 2:
		print('NO')
	else:
		print('YES')
		for j in range(len(l)):
			if l[j] >= 1:
				print(j, end=' ')
				l[j] = l[j] - 1
		for j in range(len(l) - 1, -1, -1):
			if l[j] >= 1:
				print(j, end=' ')
				l[j] = l[j] - 1
	print()
	t = t - 1


test = int(input())
while test != 0:
	size = int(input())
	numbers = list(map(int, input().split()))
	container = []
	sorted_size = sorted(numbers)
	random = 0
	z = 0
	idx = 0
	double = []
	for j in sorted_size:
		if idx == 0 or j != container[-1]:
			container.append(j)
			random = 0
			idx += 1
			continue
		if j == container[-1] and random >= 1:
			z = 2
			break
		if j == container[-1] and random == 0:
			random += 1
			z = 1
			double.append(j)
			idx += 1
			continue
	double.reverse()
	if z == 2 or (z == 1 and container[-1] == double[0]):
		print('NO')
	else:
		print('YES')
		print(*container + double)
	test -= 1


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	dic = {}
	flag = 0
	A.sort()
	for i in A:
		if i in dic:
			dic[i] += 1
			if dic[i] > 2:
				print('NO')
				flag = 1
				break
		else:
			dic[i] = 1
	if flag == 0:
		ans = []
		temp = []
		for i in dic:
			if dic[i] == 2:
				temp.append(i)
			ans.append(i)
		temp.sort()
		temp.reverse()
		if temp:
			if ans[-1] > temp[0]:
				for j in range(len(temp)):
					ans.append(temp[j])
				print('YES')
				print(*ans)
			else:
				print('NO')
		else:
			print('YES')
			print(*A)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	for i in a:
		if i in b:
			c.append(i)
		else:
			b.append(i)
	b.sort()
	c.sort(reverse=True)
	arr = b[:] + c[:]
	flag = 0
	for i in range(len(b) - 1, n - 1):
		if arr[i] == arr[i + 1]:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
		print(*arr)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().lstrip().split()))
	di = dict()
	li1 = []
	li2 = []
	ans = 'True'
	for i in range(n):
		if arr[i] in di:
			di[arr[i]] += 1
		else:
			di[arr[i]] = 1
	new_val = di.values()
	for j in di:
		if di[j] == 1:
			li1.append(j)
		elif di[j] == 2:
			li1.append(j)
			li2.append(j)
		else:
			ans = False
	li1.sort()
	li2.sort(reverse=True)
	q = li1 + li2
	for j in range(len(q) - 1):
		if q[j] != q[j + 1]:
			continue
		else:
			ans = False
	if ans == 'True':
		print('YES')
		print(*q, sep=' ')
	else:
		print('NO')


n = int(input())
for i in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	a1 = sorted(a)
	m = max(a1)
	q = dict()
	f = 0
	b = list()
	for i in a1:
		q[i] = q.get(i, 0) + 1
	for i in q:
		b.append(i)
		if i != m and q[i] > 2:
			f = 1
		if i == m and q[i] > 1:
			f = 1
		q[i] = q[i] - 1
	b1 = list()
	for i in q:
		if q[i] > 0:
			b1.append(i)
	b1 = sorted(b1, reverse=True)
	if f == 1:
		print('NO')
	else:
		print('YES')
		print(*b, end=' ')
		print(*b1)


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	flag = 1
	s = list(set(a))
	for i in s:
		if a.count(i) > 2:
			flag = 0
	if flag == 0 or a.count(m) != 1:
		print('NO')
	else:
		print('YES')
		r = []
		for i in s:
			if a.count(i) > 1:
				r.append(i)
		r = sorted(r, reverse=True)
		s1 = sorted(s) + r
		print(*s1)
	t -= 1


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	g = Counter(arr)
	s = list(g.values())
	seti = list(set(arr))
	seti = sorted(seti)
	if len(seti) == n:
		print('YES')
		print(*arr)
	else:
		h = [item for (item, count) in g.items() if count >= 3]
		if h:
			print('NO')
		elif g[arr[-1]] == 2:
			print('NO')
		else:
			k = [item for (item, count) in g.items() if count == 2]
			k = sorted(k, reverse=True)
			seti.extend(k)
			print('YES')
			print(*seti)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	y = 0
	l1 = []
	l2 = []
	l1.append(l[0])
	for i in range(1, n):
		if l[i] == l[i - 1]:
			l2.append(l[i])
		else:
			l1.append(l[i])
	for i in range(1, len(l2)):
		if l2[i] == l2[i - 1]:
			y = 1
			break
	if y == 1:
		print('NO')
	else:
		l2.reverse()
		if len(l2) != 0:
			if l1[-1] == l2[0]:
				print('NO')
				y = 2
		if y != 2:
			print('YES')
			for i in l1:
				print(i, end=' ')
			for i in l2:
				print(i, end=' ')
			print('')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ss = set(a)
	j = max(a)
	s = []
	su = []
	flag = 1
	for i in ss:
		m = a.count(i)
		if m == 1:
			s.append(i)
		elif m == 2:
			s.append(i)
			su.append(i)
		else:
			flag = 0
			break
	if a.count(j) % 2 == 0:
		flag = 0
	if flag:
		print('YES')
		s.sort()
		su.sort(reverse=True)
		print(*s + su)
	else:
		print('NO')


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = a[:]
	for i in range(n // 2):
		b[i] = a[2 * i]
		b[n - i - 1] = a[2 * i + 1]
	if n % 2 == 1:
		b[n // 2] = a[n - 1]
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			print('NO')
			return
	print('YES')
	for i in range(n):
		print(b[i], end=' ')
	print()
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = []
	a = []
	x = 0
	l.sort()
	for i in range(n):
		if x < l[i]:
			x = l[i]
			a.append(l[i])
			l[i] = 0
			continue
		b.append(l[i])
	(x, f) = (0, 0)
	for i in b:
		if x == i:
			f = 1
		x = i
	b.sort(reverse=True)
	if len(b) == 0:
		print('YES')
		print(*a)
	elif f == 1 or a[-1] == b[0]:
		print('NO')
	else:
		print('YES')
		print(*a + b)


def check():
	n = int(input())
	a = list(map(int, input().split()))
	c = set()
	d = list()
	for q in range(n):
		if a[q] in c:
			d.append(a[q])
		else:
			c.add(a[q])
	d.sort(reverse=True)
	c = list(c)
	c.sort()
	a = c[:] + d[:]
	for q in range(len(c) - 1, n - 1):
		if a[q] == a[q + 1]:
			print('NO')
			return
	print('YES')
	print(*a)
for t in range(int(input())):
	check()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cd = Counter(arr)
	if cd[max(arr)] > 1:
		print('NO')
	elif cd.most_common(1)[0][1] > 2:
		print('NO')
	else:
		uni = sorted(list(set(arr)))
		ans = ' '.join(list(map(str, uni)))
		for i in uni[::-1]:
			if cd[i] > 1:
				ans += ' ' + str(i)
		print('YES')
		print(ans)


def PrintBothArrays(a, n):
	(v1, v2) = ([], [])
	mpp = dict.fromkeys(a, 0)
	for i in range(n):
		mpp[a[i]] += 1
		if mpp[a[i]] == 1:
			v1.append(a[i])
		elif mpp[a[i]] == 2:
			v2.append(a[i])
		else:
			print('NO')
			return
	maximum = max(v1)
	if maximum in v2:
		print('NO')
		return
	v1.sort()
	print('YES')
	for it in v1:
		print(it, end=' ')
	v2.sort(reverse=True)
	for it in v2:
		print(it, end=' ')
	print()
try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		PrintBothArrays(a, n)
except EOFError as t:
	pass


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	arr = [int(hh) for hh in input().split()]
	a = set()
	b = list()
	for i in range(n):
		if arr[i] not in a:
			a.add(arr[i])
		else:
			b.append(arr[i])
	a = list(a)
	a.sort()
	b.sort(reverse=True)
	arr = a[:] + b[:]
	flag = 0
	for ii in range(len(a) - 1, n - 1):
		if arr[ii] == arr[ii + 1]:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
		print(*arr)


mod = 1000000007
T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	flag = 1
	d = {}
	a.sort()
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
		if d[i] > 2:
			flag = 0
			break
	if flag == 0:
		print('NO')
		continue
	uni = list(d.values())
	if uni.count(1) == n:
		print('YES')
		print(' '.join(map(str, a)))
	else:
		lf = []
		rt = []
		for (i, j) in d.items():
			if j == 2:
				lf.append(i)
				rt.append(i)
			else:
				lf.append(i)
		lf.sort()
		rt.sort()
		if lf == rt:
			print('NO')
		elif lf[-1] == rt[-1]:
			print('NO')
		else:
			print('YES')
			p = lf.copy()
			rt.sort(reverse=True)
			p += rt.copy()
			print(' '.join(map(str, p)))


def solve(a):
	(l1, l2) = ([], [])
	printed = False
	dic = dict.fromkeys(a, 0)
	for i in a:
		dic[i] += 1
		if dic[i] == 1:
			l1.append(i)
		if dic[i] == 2:
			l2.append(i)
		if dic[i] == 3:
			print('NO')
			return
			printed = True
			break
	if not printed:
		if max(l1) in l2:
			print('NO')
			return
		else:
			print('YES')
			l1 = sorted(l1)
			l2 = sorted(l2, reverse=True)
			print(*l1 + l2)
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	solve(a)


t = int(input())
for _ in range(t):
	n = input()
	a = list(map(lambda x: int(x), input().split()))
	hashmap = {}
	for number in a:
		if number not in hashmap:
			hashmap[number] = 0
		hashmap[number] += 1
	max_number = max(a)
	flag = 0
	for i in hashmap:
		if hashmap[i] > 2:
			print('NO')
			flag = 1
			break
		if hashmap[i] == 2 and i == max_number:
			print('NO')
			flag = 1
			break
	if flag == 0:
		print('YES')
		answer = []
		hashmap_asc = sorted(list(hashmap.keys()))
		hashmap_desc = sorted(list(hashmap.keys()), reverse=True)
		for i in range(0, len(hashmap_asc)):
			answer.append(hashmap_asc[i])
			hashmap[hashmap_asc[i]] -= 1
			if hashmap[hashmap_asc[i]] == 0:
				del hashmap[hashmap_asc[i]]
		for j in range(0, len(hashmap_desc)):
			if hashmap_desc[j] not in hashmap:
				continue
			else:
				answer.append(hashmap_desc[j])
		for i in answer:
			print(i, end=' ')
		print()


try:
	for i in range(int(input())):
		n = int(input())
		arr = [int(x) for x in input().split()]
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		ans = 0
		c = 0
		for x in sorted(d.keys()):
			if d[x] == 2 and c == len(d) - 1:
				ans = 1
				break
			elif d[x] > 2:
				ans = 1
				break
			else:
				c += 1
		if ans == 1:
			print('NO')
		else:
			li = []
			for x in sorted(d.keys()):
				li.append(x)
			for x in reversed(sorted(d.keys())):
				if d[x] == 2:
					li.append(x)
			print('YES')
			for x in li:
				print(x, end=' ')
			print()
except:
	pass


tests = int(input())
for i in range(tests):
	length = int(input())
	arr = list(map(int, input().split()))
	maximum = -10 ** 9
	increasing_arr = []
	decreasing_arr = []
	unique_dict = {}
	ans = 'YES'
	ans_arr = []
	for j in arr:
		if j in unique_dict:
			if unique_dict[j] > 1:
				ans = 'NO'
				break
			unique_dict[j] += 1
			decreasing_arr.append(j)
		else:
			unique_dict[j] = 1
			increasing_arr.append(j)
		maximum = max(maximum, j)
	if unique_dict[maximum] > 1:
		ans = 'NO'
	if ans != 'NO':
		ans_arr.extend(sorted(increasing_arr))
		ans_arr.extend(sorted(decreasing_arr, reverse=True))
		print(ans)
		print(*ans_arr)
	else:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.append(0)
	l.sort()
	l1 = []
	l2 = []
	c = 0
	flag = 0
	for i in range(1, n + 1):
		if l[i] == l[i - 1]:
			l2.append(l[i])
			c += 1
		else:
			l1.append(l[i])
			c = 1
		if c == 3 or (i == n and c == 2):
			print('NO')
			flag = 1
			break
	if flag == 0:
		l2.reverse()
		l3 = l1 + l2
		print('YES')
		print(*l3, sep=' ')


test = int(input())
while test != 0:
	size = int(input())
	numbers = list(map(int, input().split()))
	container = []
	double = []
	sorted_size = sorted(numbers)
	flag = False
	for j in sorted_size:
		if len(container) == 0 or j != container[-1]:
			container.append(j)
		elif len(double) == 0 or j != double[-1]:
			double.append(j)
		else:
			flag = True
			break
	double.reverse()
	if flag or (len(double) != 0 and container[-1] == double[0]):
		print('NO')
	else:
		print('YES')
		print(*container + double)
	test -= 1


from collections import deque

def check_function(arr):
	n = len(arr)
	if n == 1:
		return (True, arr)
	arr.sort()
	left_deque = deque()
	right_deque = deque()
	for el in arr:
		try:
			if left_deque[-1] != el:
				left_deque.append(el)
			elif right_deque[0] != el:
				right_deque.appendleft(el)
			else:
				return (False, arr)
		except IndexError:
			if not left_deque:
				left_deque.append(el)
			elif not right_deque:
				right_deque.appendleft(el)
	if right_deque and right_deque[0] == left_deque[-1]:
		return (False, arr)
	return (True, left_deque + right_deque)
T = int(input().strip())
for _ in range(T):
	N = int(input().strip())
	arr = list(map(int, input().strip().split()))
	ans = check_function(arr)
	if ans[0]:
		print('YES')
		print(' '.join(list(map(str, ans[1]))))
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	d = {}
	for i in a:
		try:
			if d[i]:
				d[i] += 1
		except KeyError:
			d[i] = 1
	z = 0
	for i in d:
		if d[i] > 2:
			z = 1
			break
		elif d[i] == 2:
			z = 2
	if z == 1:
		print('NO')
	elif z == 0:
		print('YES')
		for i in a:
			print(i, end=' ')
		print()
	elif d[max(a)] == 1:
		print('YES')
		for i in d:
			if d[i] >= 1:
				print(i, end=' ')
				d[i] -= 1
		a = []
		for i in d:
			if d[i] >= 1:
				a.append(i)
				d[i] -= 1
		for i in range(len(a) - 1, -1, -1):
			print(a[i], end=' ')
		print()
	else:
		print('NO')


from heapq import heapify, heappop, heappush
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	h1 = set()
	h2 = set()
	mx = -10000000000.0
	mx_cnt = 0
	flg = 0
	for i in range(len(a)):
		a_ = a[i]
		if a_ > mx:
			mx = a_
			mx_cnt = 1
		elif a_ == mx:
			mx_cnt += 1
		if a_ not in h1:
			h1.add(a_)
		elif a_ not in h2:
			h2.add(a_)
		else:
			print('NO')
			flg = 1
			break
	if flg == 0:
		if mx_cnt > 1:
			print('NO')
		else:
			print('YES')
			h1 = list(h1)
			h2 = list(h2)
			h1.sort()
			h2.sort(reverse=True)
			h = h1 + h2
			print(*h)


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()))
	l1 = []
	l2 = []
	c = Counter(l)
	for (x, y) in c.items():
		if y > 2:
			print('NO')
			break
		if y == 2:
			l1.append(x)
		l2.append(x)
	else:
		if max(l2) in l1:
			print('NO')
		else:
			l2.sort()
			l1.sort(reverse=True)
			print('YES')
			print(*l2, *l1)


def ans():
	n = int(input())
	a = list(map(int, input().split()))
	t = max(set(a), key=a.count)
	maxi = max(a)
	if a.count(maxi) > 1:
		print('NO')
		return
	cou = a.count(t)
	lis = []
	a.sort()
	b = set(a)
	if cou > 2:
		print('NO')
		return
	elif cou == 1:
		print('YES')
		for i in a:
			print(i, end=' ')
		print()
		return
	else:
		for i in b:
			if a.count(i) == 2:
				a.remove(i)
				lis.append(i)
			else:
				continue
	lis.sort(reverse=True)
	d = a + lis
	print('YES')
	for i in d:
		print(i, end=' ')
	print()
	return
t = int(input())
while t > 0:
	ans()
	t -= 1


def inc_dec(arr):
	if len(arr) == len(set(arr)):
		print('YES')
		print(*sorted(arr))
		return
	hash = {}
	for i in arr:
		if i in hash:
			hash[i] += 1
		else:
			hash[i] = 1
	lastval = 0
	for j in hash.values():
		if j > 2:
			print('NO')
			return
		lastval = j
	fh = sorted(hash)
	sh = []
	for k in fh:
		if hash[k] > 1:
			sh.append(k)
	resul = fh + sh[::-1]
	for k in range(len(resul) - 1):
		if resul[k] == resul[k + 1]:
			print('NO')
			return
	else:
		print('YES')
		print(*resul)
T = int(input())
while T:
	dump = input()
	a = list(map(int, input().split()))
	inc_dec(a)
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	sw = dict()
	flag = True
	for j in lst:
		sw[j] = sw.get(j, 0) + 1
		if sw[j] > 2:
			flag = False
			break
	if sw[max(sw.keys())] > 1:
		print('NO')
		continue
	if flag == False:
		print('NO')
		continue
	sw_ = dict()
	for (d, j) in sw.items():
		if j == 2:
			sw_[d] = sw_.get(d, 0) + 1
	print('YES')
	for j in sorted(sw.keys()):
		print(j, end=' ')
	for j in sorted(sw_.keys(), reverse=True):
		print(j, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	l.sort()
	p = list(set(l))
	p.sort()
	f = 0
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	if len(d) == n:
		print('YES')
		for i in l:
			print(i, end=' ')
		print()
	else:
		t = p[:]
		for i in range(len(t) - 1, -1, -1):
			d[t[i]] -= 1
			if i == len(t) - 1:
				if d[t[i]] != 0:
					f = 1
					break
			elif d[t[i]] >= 2:
				f = 1
				break
			elif d[t[i]] != 0:
				t.append(t[i])
		if f == 1:
			print('NO')
		else:
			print('YES')
			for i in t:
				print(i, end=' ')
			print()


from collections import Counter

def fn(a):
	c = Counter(a)
	single = []
	double = []
	for i in c.keys():
		if c[i] > 2:
			return 0
		if c[i] == 2:
			double.append(i)
		single.append(i)
	single.sort()
	double.sort(reverse=True)
	try:
		if single[-1] == double[0]:
			return 0
	except:
		pass
	return single + double
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g = fn(a)
	if g:
		print('YES')
		print(*g)
	else:
		print('NO')


test = int(input())
for tes in range(test):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	freq = {}
	flag = True
	for num in arr:
		if num in freq:
			freq[num] += 1
			if freq[num] > 2:
				flag = False
				break
		else:
			freq[num] = 1
	if freq[max(list(freq.keys()))] > 1:
		flag = False
	if flag:
		print('YES')
		rem = []
		for num in sorted(list(freq.keys())):
			print(num, end=' ')
			if freq[num] == 2:
				rem.append(num)
		for num in reversed(sorted(rem)):
			print(num, end=' ')
		print()
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	f = True
	d = {}
	for j in l:
		if d.get(j) is None:
			d[j] = 1
		else:
			d[j] += 1
			if d[j] > 2:
				f = False
				break
	s = []
	ans = [l[0]]
	if f and d[l[-1]] == 1:
		for k in range(1, n):
			if l[k] == l[k - 1]:
				s.append(l[k])
			else:
				ans.append(l[k])
		for z in range(len(s) - 1, -1, -1):
			ans.append(s[z])
		print('YES')
		print(*ans)
	else:
		print('NO')


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

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list_input()
	a.sort()
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	ans = [0] * n
	flag = 0
	(j, k) = (0, n - 1)
	for i in d:
		if d[i] > 2:
			flag = 1
			break
		elif d[i] == 2:
			if j == k - 1:
				flag = 1
				break
			ans[j] = i
			ans[k] = i
			j += 1
			k -= 1
		else:
			ans[j] = i
			j += 1
	if flag == 1:
		print('NO')
	else:
		print('YES')
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	na = [arr[0]] * n
	l = 1
	r = n - 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			na[r] = arr[i]
			r -= 1
		else:
			na[l] = arr[i]
			l += 1
	for i in range(1, n):
		if na[i - 1] == na[i]:
			print('NO')
			break
	else:
		print('YES')
		print(*na, sep=' ')


for _ in range(int(input())):
	N = int(input())
	arr = map(int, input().split())
	arr = sorted(arr)
	mp = dict()
	for i in arr:
		if i in mp:
			mp[i] += 1
		else:
			mp[i] = 1
		if mp[i] == 3:
			print('NO')
			break
	else:
		if mp[arr[-1]] == 2:
			print('NO')
		else:
			print('YES')
			for i in list(mp.items())[:]:
				print(i[0], end=' ')
				if mp[i[0]] == 1:
					del mp[i[0]]
			for i in list(mp.items())[::-1]:
				print(i[0], end=' ')
			print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	f = []
	l = []
	flag = 0
	for i in a:
		if i not in d:
			f.append(i)
			d[i] = 1
		else:
			l.append(i)
			d[i] += 1
			if d[i] > 2:
				flag = 1
				break
	if flag == 1:
		print('NO')
		continue
	f.sort()
	l.sort()
	if len(l) == 0:
		print('YES')
		print(*f)
	elif f[len(f) - 1] == l[len(l) - 1]:
		print('NO')
	else:
		l.reverse()
		print('YES')
		print(*f, end=' ')
		print(*l)


from typing import Counter
for _ in range(int(input())):
	n = int(input())
	nli = list(map(int, input().split()))
	mx = max(nli)
	nli.remove(mx)
	lhs = []
	rhs = []
	countr = Counter(nli)
	ps = True
	if mx in nli:
		print('NO')
	else:
		for (key, value) in countr.items():
			if value == 1:
				lhs.append(key)
			elif value == 2:
				lhs.append(key)
				rhs.append(key)
			elif value > 2:
				ps = False
				break
		if ps:
			lhs.sort()
			lhs.append(mx)
			rhs.sort(reverse=True)
			li = lhs + rhs
			print('YES')
			print(*li)
		else:
			print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	left = {}
	center = max(ls)
	right = {}
	for i in ls:
		if i == center:
			if not left.get(center):
				left[center] = True
			else:
				print('NO')
				break
		elif not left.get(i):
			left[i] = True
		elif not right.get(i):
			right[i] = True
		else:
			print('NO')
			break
	else:
		ans = []
		tmp = list(left.keys())
		tmp.sort()
		ans.extend(tmp)
		tmp = list(right.keys())
		tmp.sort(reverse=True)
		ans.extend(tmp)
		print('YES')
		for i in ans:
			print(i, '', end='')
		print()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	for i in a:
		if i in b:
			c.append(i)
		else:
			b.append(i)
	b.sort()
	c.sort(reverse=True)
	flag = 0
	d = Counter(c)
	for i in d.values():
		if i > 1 or c[0] == b[-1]:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
		b.extend(c)
		print(*b)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	d = {}
	for i in arr:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	flag = True
	for i in d:
		if d[i] > 2:
			flag = False
			break
	if arr.count(max(arr)) != 1:
		flag = False
	if flag == True:
		arr1 = []
		arr2 = []
		for i in d:
			if d[i] <= 2:
				if d[i] == 2:
					arr2.append(i)
				arr1.append(i)
		arr2.reverse()
		rearr = arr1 + arr2
		print('YES')
		print(*rearr)
	else:
		print('NO')


from collections import Counter, deque
for T in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	flag = True
	count = Counter(A)
	if count[max(A)] > 1 or count.most_common(1)[0][1] > 2:
		print('NO')
		flag = False
	if flag:
		print('YES')
		nums = sorted(count.keys())
		ans = deque()
		ans.append(nums.pop())
		while nums:
			curr = nums.pop()
			ans.append(curr)
			if count[curr] == 2:
				ans.appendleft(curr)
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	m = 0
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
		if i > m:
			m = i
	if a.count(m) > 1:
		print('NO')
	else:
		for i in d.values():
			if i > 2:
				print('NO')
				break
		else:
			del d[m]
			l = []
			r = []
			for i in d:
				if d[i] == 2:
					r.append(i)
				l.append(i)
			l.sort()
			r.sort(reverse=True)
			print('YES')
			print(' '.join((str(x) for x in l)), m, ' '.join((str(x) for x in r)))


def ques2(n, a):
	flag = 1
	b = []
	f = []
	d = {}
	for i in a:
		d[i] = d.get(i, 0) + 1
		if d[i] > 2:
			flag = 0
			break
		elif d[i] == 2:
			b.insert(0, i)
		else:
			f.append(i)
	f = sorted(f)
	b = sorted(b, reverse=True)
	if flag == 0 or (b != [] and f[-1] == b[0]):
		print('NO')
	else:
		print('YES')
		print(*f, *b)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = ques2(n, a)
	ans


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	x = max(list1)
	map1 = dict()
	ans = 1
	ans1 = []
	ans2 = []
	for val in list1:
		if val not in map1:
			map1[val] = 1
			ans1.append(val)
		elif map1[val] == 1 and val != x:
			map1[val] += 1
			ans2.append(val)
		else:
			ans = 0
			break
	if ans:
		print('YES')
		ans1.sort()
		ans2.sort()
		for i in range(len(ans1)):
			print(ans1[i], end=' ')
		for i in range(len(ans2) - 1, 0 - 1, -1):
			print(ans2[i], end=' ')
		print()
	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 = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

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

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		f = dd(int)
		f1 = 0
		for i in a:
			f[i] += 1
			if f[i] > 2:
				f1 = 1
		if f[max(a)] > 1 or f1:
			print('NO')
			continue
		a = [i for i in f.keys()]
		a.sort()
		print('YES')
		print(*a, end=' ')
		a.reverse()
		for i in a:
			if f[i] > 1:
				print(i, end=' ')
		print()
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


ted = int(input())
for i in range(ted):
	n = int(input())
	lis = list(map(int, input().split()))
	dict1 = {}
	state = False
	lis.sort()
	for i in range(len(lis)):
		if lis[i] in dict1:
			dict1[lis[i]] += 1
		else:
			dict1[lis[i]] = 1
		if dict1[lis[i]] > 2:
			state = True
			break
		if lis[len(lis) - 1] in dict1:
			if dict1[lis[len(lis) - 1]] > 1:
				state = True
				break
	if state:
		print('NO')
		continue
	inc = []
	dec = []
	for (i, j) in dict1.items():
		if j > 1:
			inc.append(i)
			dec.insert(0, i)
		else:
			inc.append(i)
	print('YES')
	for i in inc + dec:
		print(i, end=' ')
	print()


limit = 2 * pow(10, 5)

def get_ans(n, arr):
	arr.sort()
	count = [0] * (limit + 1)
	l1 = []
	l2 = []
	max_n = 0
	for num in arr:
		max_n = max(max_n, num)
		if count[num] == 0:
			l1.append(num)
		elif count[num] == 1:
			l2.append(num)
		else:
			print('NO')
			return
		count[num] += 1
	if count[max_n] > 1:
		print('NO')
		return
	else:
		print('YES')
		print(*l1, *reversed(l2))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	get_ans(n, arr)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dct = Counter(arr)
	if dct[max(arr)] > 1:
		print('NO')
	else:
		for i in dct:
			if dct[i] > 2:
				print('NO')
				break
		else:
			print('YES')
			t = set(arr)
			first_half = sorted(list(t))
			for i in dct:
				if dct[i] == 1:
					t.remove(i)
			first_half.extend(sorted(t, reverse=True))
			for i in first_half:
				print(i, end=' ')
			print()


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = Counter(arr)
	keys = sorted(a.keys())
	ans = []
	ind = True
	for i in keys[:-1]:
		if a[i] == 1 or a[i] == 2:
			a[i] -= 1
			ans.append(i)
		else:
			ind = False
			break
	if a[keys[-1]] > 1:
		ind = False
	else:
		ans.append(keys[-1])
	if not ind:
		print('NO')
		continue
	for i in keys[-2::-1]:
		if a[i] == 1:
			a[i] -= 1
			ans.append(i)
	print('YES')
	print(' '.join(list(map(str, ans))))


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = li()
	m = max(a)
	c = Counter(a)
	b = list(set(a))
	b.sort()
	for i in range(len(b) - 1):
		if c[b[i]] > 2:
			print('NO')
			return
	if c[b[-1]] > 1:
		print('NO')
		return
	print('YES')
	for i in b:
		print(i, end=' ')
		c[i] -= 1
	for i in range(len(b) - 2, -1, -1):
		if c[b[i]]:
			print(b[i], end=' ')
	print()
for _ in range(I()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	g = list(set(arr))
	g.sort()
	arr.sort()
	if len(g) == n:
		print('YES')
		print(*arr)
	else:
		f = 0
		k = []
		for i in g:
			c = arr.count(i)
			if c >= 3:
				f = 1
				break
			elif c == 2 and i == arr[-1]:
				f = 1
				break
			elif c == 2:
				k.append(i)
		k = sorted(k, reverse=True)
		g.extend(k)
		if f == 0:
			print('YES')
			print(*g)
		else:
			print('NO')


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	cache = dict()
	maxi = max(s)
	for ele in arr:
		if ele in cache:
			cache[ele] += 1
		else:
			cache[ele] = 1
	if cache[maxi] > 1:
		print('NO')
	else:
		for k in cache:
			if cache[k] > 2:
				print('NO')
				break
		else:
			print('YES')
			l1 = sorted(list(s))
			for k in cache:
				if cache[k] == 1:
					s.remove(k)
			l2 = sorted(list(s), reverse=True)
			print(' '.join(map(str, l1 + l2)))
	t -= 1


t = int(input())
for q in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	d = {}
	lala = []
	for i in l:
		if i in d:
			d[i] += 1
			lala.append(i)
		else:
			d[i] = 1
	lala = sorted(lala, reverse=True)
	if max(d.values()) > 2 or d[l[-1]] == 2:
		print('NO')
	else:
		print('YES')
		for i in d:
			if d[i] != 0:
				print(i, end=' ')
				d[i] -= 1
		for i in lala:
			print(i, end=' ')
		print('')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = []
	b = []
	flag = True
	ans.append(a[0])
	for i in range(1, n):
		if a[i] == a[i - 1]:
			if i != n - 1:
				if a[i] == a[i + 1]:
					flag = False
					print('NO')
					break
				else:
					b.append(a[i])
			else:
				flag = False
				print('NO')
				break
		else:
			ans.append(a[i])
	b.sort(reverse=True)
	if flag:
		print('YES')
		if b:
			print(*ans, end=' ')
			print(*b)
		else:
			print(*ans)


t = int(input())
for _ in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	B = [0] * N
	A.sort()
	B[0] = A[0]
	flag = 1
	count = 0
	j = 1
	i = 1
	k = N - 1
	while i < N:
		if A[i] != A[i - 1]:
			count = 0
			B[j] = A[i]
			j += 1
		elif count >= 1:
			flag = 0
			break
		else:
			count += 1
			B[k] = A[i]
			k -= 1
		i += 1
	for i in range(1, N):
		if B[i] == B[i - 1]:
			flag = 0
			break
	if not flag:
		print('NO')
	else:
		print('YES')
		for i in B:
			print(i, end=' ')
		print()


t = int(input())
while t > 0:
	n = int(input())
	lst = list(map(int, input().split()))
	inc = set()
	(dec, flag) = ([], 0)
	for i in range(n):
		if lst[i] not in inc:
			inc.add(lst[i])
		else:
			dec.append(lst[i])
	inc = list(inc)
	inc.sort()
	dec.sort(reverse=True)
	arr = inc + dec
	for i in range(len(inc) - 1, len(arr) - 1):
		if arr[i] == arr[i + 1]:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')
		print(*arr)
	t -= 1