An array $a$ is called ugly if it contains at least one element which is equal to the sum of all elements before it. If the array is not ugly, it is beautiful.

For example:

the array $[6, 3, 9, 6]$ is ugly: the element $9$ is equal to $6 + 3$;

the array $[5, 5, 7]$ is ugly: the element $5$ (the second one) is equal to $5$;

the array $[8, 4, 10, 14]$ is beautiful: $8 \ne 0$, $4 \ne 8$, $10 \ne 8 + 4$, $14 \ne 8 + 4 + 10$, so there is no element which is equal to the sum of all elements before it.

You are given an array $a$ such that $1 \le a_1 \le a_2 \le \dots \le a_n \le 100$. You have to reorder the elements of $a$ in such a way that the resulting array is beautiful. Note that you are not allowed to insert new elements or erase existing ones, you can only change the order of elements of $a$. You are allowed to keep the array $a$ unchanged, if it is beautiful.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases.

Each test case consists of two lines. The first line contains one integer $n$ ($2 \le n \le 50$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 100$).


-----Output-----

For each test case, print the answer as follows:

if it is impossible to reorder the elements of $a$ in such a way that it becomes beautiful, print NO;

otherwise, in the first line, print YES. In the second line, print $n$ integers — any beautiful array which can be obtained from $a$ by reordering its elements. If there are multiple such arrays, print any of them.


-----Examples-----

Input
4
4
3 3 6 6
2
10 10
5
1 2 3 4 5
3
1 4 4
Output
YES
3 6 3 6
NO
YES
2 4 1 5 3
YES
1 4 4


-----Note-----

None

Difficulty: EASY
Tags: Sorting

Mathematics

Constructive algorithms
Skill types: Sorting

Starter code:

Solutions:
for time in range(int(input())):
	n = input()
	a = [k for k in input().split()]
	if a[0] == a[-1]:
		print('NO')
		continue
	if len(a) == 2:
		(a[0], a[1]) = (a[1], a[0])
	else:
		(a[1], a[-1]) = (a[-1], a[1])
	print('YES')
	print(' '.join(a))


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


for t in range(int(input())):
	n = int(input())
	a = list(map(str, input().split()))
	b = a.count(a[-1])
	if b > 1 and n - b > 0:
		print('YES')
		print(' '.join([a[-1]] + a[:-b] + a[-b + 1:]))
	elif a[-1] != a[-2]:
		print('YES')
		print(' '.join(reversed(a)))
	else:
		print('NO')


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


t = int(input())
result = []
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split(' ')))
	ai.sort()
	ai.reverse()
	ci = list(map(str, ai))
	if ai[0] != ai[1]:
		result.append('YES')
		result.append(' '.join(ci))
	elif (ai[0] == ai[1]) & (ai[0] != ai[-1]):
		result.append('YES')
		result.append(ci[-1] + ' ' + ' '.join(ci[1:n - 1]) + ' ' + ci[0])
	else:
		result.append('NO')
for i in result:
	print(i)


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


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	if len(set(arr)) == 1:
		print('NO')
		continue
	print('YES')
	(arr[1], arr[-1]) = (arr[-1], arr[1])
	print(' '.join(list(map(str, arr))))


import sys

def is_ugly(arr):
	sm = arr[0]
	for i in range(1, len(arr)):
		if sm == arr[i]:
			return True
		sm += arr[i]
	return False

def main(input, print):
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		ugly = is_ugly(arr)
		if not ugly:
			print('YES' + '\n')
			print(' '.join(map(str, arr)) + '\n')
		else:
			(arr[0], arr[-1]) = (arr[-1], arr[0])
			if arr[0] == arr[1]:
				print('NO' + '\n')
			else:
				print('YES' + '\n')
				print(' '.join(map(str, arr)) + '\n')
main(sys.stdin.readline, sys.stdout.write)


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	nums = inlt()
	nums.sort()
	(i, j) = (0, len(nums) - 1)
	if nums[i] == nums[n - 1]:
		print('NO')
	elif nums.count(nums[n - 1]) > 1:
		flag = True
		while i <= j:
			if nums[i] != 0 and nums[i] != nums[j]:
				(nums[i], nums[j]) = (nums[j], nums[i])
				print('YES')
				print(' '.join(list(map(str, reversed(nums)))))
				flag = False
				break
		if flag:
			print('NO')
	else:
		print('YES')
		print(' '.join(list(map(str, reversed(nums)))))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(a[0]) == len(a):
		print('NO')
	else:
		print('YES')
		mah = a.pop(a.index(max(a)))
		print(mah, ' '.join([str(x) for x in a]))


def beautify(arr, l):
	arr = arr[::-1]
	if arr[0] != arr[1]:
		print('YES')
		return arr
	elif arr[-1] == arr[0]:
		print('NO')
		return None
	else:
		t = arr[-1]
		arr[-1] = arr[1]
		arr[1] = t
		print('YES')
		return arr
	print('NO')
	return None
test = int(input())
for _ in range(test):
	l = int(input())
	array = list(map(int, input().split()))
	b = beautify(array, l)
	if b != None:
		print(' '.join(list(map(str, b))))


def reorder(array: list):
	max_element = array[-1]
	array.insert(0, max_element)
	return array[:-1]

def is_ugly(a):
	if a[0] == a[1]:
		return True
	else:
		return False

def list_to_string(array):
	array = [str(i) for i in array]
	return ' '.join(array)
t = int(input())
for _ in range(t):
	length = int(input())
	a = list(map(int, input().split()))
	reordered_a = reorder(a)
	if is_ugly(reordered_a):
		print('NO')
	else:
		print('YES')
		print(list_to_string(reordered_a))


for _ in range(int(input())):
	(_, arr) = (input(), sorted(map(int, input().split())))
	arr.insert(0, arr.pop())
	if arr[0] == arr[1]:
		print('NO')
	else:
		print(f"YES\n{' '.join(map(str, arr))}")


import bisect
import heapq
import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print('NO')
		continue
	a = sorted(a, reverse=True)
	c = a.count(a[0])
	a = a[:1] + a[c:] + a[1:c]
	print('YES')
	print(' '.join(map(str, a)))


for tcase in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	b = [a.pop()]
	b += a
	if b[0] == b[1]:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, b)))


from collections import defaultdict
from sys import stdin, stdout
import string
from math import factorial

def solution(A):
	if len(set(A)) == 1:
		print('NO')
		return
	sorted_a = sorted(A, reverse=True)
	if sorted_a[0] == sorted_a[1]:
		sorted_a[1] = sorted_a[-1]
		sorted_a[-1] = sorted_a[0]
	print('YES')
	print(' '.join(map(str, sorted_a)))
test_cases = int(stdin.readline())
for it in range(test_cases):
	N = int(stdin.readline().strip())
	A = list(map(int, stdin.readline().split()))
	solution(A)


t = int(input())
for i in range(t):
	n = int(input())
	numbers = [int(num) for num in input().split(' ', n - 1)]
	numbers.sort()
	numbers.reverse()
	if numbers[n - 1] == numbers[0]:
		print('NO')
	else:
		print('YES')
		while True:
			k = numbers[1]
			if k == numbers[0]:
				numbers.pop(1)
				numbers.append(k)
			else:
				break
		print(' '.join([str(elem) for elem in numbers]))


t = int(input())
for i in range(t):
	n = int(input())
	numbers = [int(num) for num in input().split(' ', n - 1)]
	numbers.sort()
	numbers.reverse()
	if numbers[0] == numbers[n - 1]:
		print('NO')
	else:
		print('YES')
		numbers.insert(0, numbers[n - 1])
		numbers.pop()
		print(' '.join([str(elem) for elem in numbers]))


ts = int(input())
for _ in range(ts):
	n = input()
	arr = map(int, input().split())
	arr = sorted(arr)[::-1]
	(arr[1], arr[-1]) = (arr[-1], arr[1])
	if arr[0] != arr[1]:
		print('YES')
		print(' '.join(map(str, arr)))
	else:
		print('NO')


t = int(input())
loo = []
for i in range(t):
	n = int(input())
	a = input().split()
	for j in range(n):
		a[j] = int(a[j])
	beauty = True
	if a[-1] == a[0]:
		beauty = False
	if beauty:
		loo.append(('YES', [a[-1]] + a[:len(a) - 1]))
	else:
		loo.append(('NO',))
for e in loo:
	if e[0] == 'YES':
		print(e[0])
		print(' '.join([str(e2) for e2 in e[1]]))
	else:
		print(e[0])


test_cases = int(input())
while test_cases:
	test_cases -= 1
	array_len = int(input())
	arr = [int(x) for x in input().split(' ')]
	arr.sort()
	rev_arr = arr[::-1]
	if arr[0] == arr[-1]:
		print('NO')
	else:
		print('YES')
		rev_arr = [str(x) for x in rev_arr]
		fin_str = ' '.join(rev_arr[1:-1])
		print(f'{rev_arr[0]} {rev_arr[-1]} {fin_str}')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if len(a) > 1 and a[0] == a[1]:
		if a[0] == a[-1]:
			print('NO')
			continue
		a = [a[0]] + [a[-1]] + a[1:-1]
	print('YES')
	print(' '.join(map(str, a)))


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	s = a.split()
	if int(s[0]) == int(s[n - 1]):
		print('NO')
	else:
		x = s[0]
		del s[0]
		s.append(x)
		s.reverse()
		st = ''
		for j in range(n):
			st = st + s[j] + ' '
		print('YES')
		print(st)


t = int(input())
res = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		res.append('NO')
		continue
	a = a[::-1]
	if len(a) > 1 and a[0] == a[1]:
		e = a.pop()
		a.insert(0, e)
	res.append('YES')
	res.append(' '.join(map(str, a)))
for i in res:
	print(i)


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


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		L = list(map(int, input().split()))
		a = max(L)
		counter = 0
		for i in range(n):
			if L[i] == a:
				counter += 1
		if counter == n:
			print('NO')
		else:
			L.sort(reverse=True)
			L = L[counter - 1:] + [a] * (counter - 1)
			for i in range(n):
				L[i] = str(L[i])
			print('YES')
			print(' '.join(L))
main()


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	new = a.copy()
	new.sort()
	new.reverse()
	if new[0] != new[1]:
		st = ' '.join([str(k) for k in new])
		sys.stdout.write('YES\n')
		sys.stdout.write(st + '\n')
	else:
		c = 0
		for j in range(n):
			if new[j] == new[0]:
				c += 1
			else:
				break
		if c == n:
			sys.stdout.write('NO\n')
		else:
			new = [new[0]] + [new[c]] + new[1:c] + new[c + 1:]
			st = ' '.join([str(k) for k in new])
			sys.stdout.write('YES\n')
			sys.stdout.write(st + '\n')


tests = int(input())
for i in range(tests):
	n = int(input())
	a = [int(k) for k in input().split()]
	a.sort(reverse=True)
	a1 = a[1]
	an1 = a[n - 1]
	if an1 == a[0]:
		print('NO')
	else:
		if a[1] == a[0]:
			a[n - 1] = a1
			a[1] = an1
		print('YES')
		print(' '.join([str(k) for k in a]))


from collections import Counter
t = int(input())
arrays = []
for _ in range(t):
	input()
	arrays.append([int(x) for x in input().split(' ')])
for array in arrays:
	if len(set(array)) <= 1:
		print('NO')
		continue
	array = sorted(array, reverse=True)
	if array[0] == array[1]:
		x = array[-1]
		array[-1] = array[0]
		array[0] = x
	print('YES')
	print(' '.join(map(str, array)))


def main():
	T = int(input())
	for i in range(T):
		_ = input()
		array = list(map(int, input().split()))
		array.sort(reverse=True)
		(array[1], array[-1]) = (array[-1], array[1])
		if array[0] == array[1]:
			print('NO')
		else:
			print('YES')
			print(' '.join(map(str, array)))
main()


n = int(input())
for i in range(n):
	input()
	l = list(map(int, input().split()))
	uniq_l = set(l)
	if len(uniq_l) == 1:
		print('NO')
	elif len(uniq_l) == len(l):
		print('YES')
		print(' '.join(map(str, sorted(l, reverse=True))))
	else:
		l = sorted(l, reverse=True)
		if l[0] == l[1]:
			(l[1], l[-1]) = (l[-1], l[1])
		print('YES')
		print(' '.join(map(str, l)))


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


n = int(input())
for i in range(n):
	s = ''
	a = int(input())
	list = input()
	list = list.split()
	max = list[a - 1]
	min = list[0]
	if min == max:
		print('NO')
	else:
		x = list[1]
		list[a - 1] = x
		list[0] = max
		list[1] = min
		for i2 in range(len(list)):
			s = s + list[i2] + ' '
		print('YES')
		print(s)


import sys

def main():
	for _ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		A.reverse()
		if A[0] == A[-1]:
			print('NO')
		else:
			(A[1], A[-1]) = (A[-1], A[1])
			print('YES')
			print(' '.join(map(str, A)))
sys.exit(main())


def reverse(seq, start, stop):
	size = stop + start
	for i in range(start, (size + 1) // 2):
		j = size - i
		(seq[i], seq[j]) = (seq[j], seq[i])
for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	s.sort(reverse=True)
	if len(set(s)) == 1:
		print('NO')
	else:
		print('YES')
		reverse(s, 1, len(s) - 1)
		print(' '.join(map(str, s)))


import sys
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, sys.stdin.readline().strip().split()), reverse=True)
	if a[0] != a[-1]:
		a = [a[0]] + [a[-1]] + a[1:-1]
		sys.stdout.write('YES\n')
		sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
		continue
	sys.stdout.write('NO\n')


def main(a):
	if a[0] == a[-1]:
		print('NO')
		return
	n = len(a)
	first = a[:n // 2]
	last = a[-n // 2:]
	last.reverse()
	ans = []
	for (x1, x2) in zip(first, last):
		ans.append(x1)
		ans.append(x2)
	if n % 2 == 1:
		ans.append(a[n // 2])
	print('YES')
	print(' '.join([str(x) for x in ans]))
tests = int(input())
for _ in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	main(a)


import sys

def fn(n):
	max_val = max(n)
	filtered = list(filter(lambda x: x != max_val, n))
	if not filtered:
		return ('NO', None)
	a = n.copy()
	a.remove(filtered[0])
	returned = [filtered[0]] + sorted(a, reverse=True)
	output = ''
	for item in returned:
		output += str(item) + ' '
	return ('YES', output[:-1])
input = sys.stdin.readlines()
for i in range(int(input[0].strip('\n'))):
	a = [int(x) for x in input[2 * i + 2].strip('\n').split(' ')]
	(ans, lis) = fn(a)
	print(ans)
	if ans == 'YES':
		print(lis)


def solve(a):
	a.sort(reverse=True)
	if len(a) >= 2:
		if a[0] == a[1]:
			(a[0], a[len(a) - 1]) = (a[len(a) - 1], a[0])
	s = 0
	for i in range(len(a)):
		if a[i] == s:
			print('NO')
			return
		s += a[i]
	print('YES')
	print(' '.join((str(x) for x in a)))
t = int(input())
for x in range(t):
	l = input()
	a = list(map(int, input().split()))
	solve(a)


t = int(input())
for tc in range(t):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	arr.sort(reverse=True)
	if arr[0] == arr[-1]:
		print('NO')
	else:
		print('YES')
		if arr[0] == arr[1]:
			temp = arr[-1]
			arr[-1] = arr[1]
			arr[1] = temp
		print(' '.join([str(x) for x in arr]))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		tmp = [int(x) for x in input().split()]
		if tmp[0] == tmp[-1]:
			print('NO')
		else:
			print('YES')
			ans = sorted(tmp, reverse=True)
			(ans[1], ans[-1]) = (ans[-1], ans[1])
			print(' '.join(map(str, ans)))
main()


def solve(arr):
	if len(arr) > 2 and len(set(arr)) > 1:
		print('YES')
		vals = [_ for _ in range(len(arr))]
		(s, f) = (0, len(arr) - 1)
		c = 0
		while s < f:
			vals[c] = arr[s]
			c += 1
			vals[c] = arr[f]
			c += 1
			s += 1
			f -= 1
		if s == f:
			vals[c] = arr[s]
		print(' '.join([str(_) for _ in vals]))
		return
	if len(arr) < 3 and len(set(arr)) == len(arr):
		print('YES')
		print(' '.join([str(_) for _ in arr]))
		return
	print('NO')
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(_) for _ in input().split()]
	solve(arr)


from collections import defaultdict

def check_array(aa):
	prefix_sum = 0
	for a in aa:
		if prefix_sum == a:
			return False
		prefix_sum += a
	return True

def solve(aa):
	aa_sorted = sorted(aa, reverse=True)
	if len(aa_sorted) <= 1:
		return (True, aa_sorted)
	if aa_sorted[0] != aa_sorted[1]:
		return (True, aa_sorted)
	if aa_sorted[0] != aa_sorted[-1]:
		return (True, [aa_sorted[0], aa_sorted[-1]] + aa_sorted[1:-1])
	return (False, aa)
n_tests = int(input())
for test_n in range(n_tests):
	n = int(input())
	aa = list(map(int, input().split(' ')))
	assert len(aa) == n
	(check_result, reordered_aa) = solve(aa)
	assert check_result == check_array(reordered_aa)
	if check_result:
		print('YES')
		print(' '.join(map(str, reordered_aa)))
	else:
		print('NO')


def f():
	num_of_nums = int(input())
	for _ in range(num_of_nums):
		_ = input()
		nums = list(map(int, input().split()))
		nums = sorted(nums, reverse=True)
		if nums[0] == nums[1]:
			if nums[0] == nums[-1]:
				print('NO')
				continue
			else:
				nums.insert(0, nums.pop())
		print('YES')
		print(' '.join(map(str, nums)))
f()


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr[0] != arr[1]:
		print('YES')
		print(' '.join([str(i) for i in arr]))
	else:
		tracker = False
		for i in range(1, n):
			if arr[0] != arr[i]:
				(arr[0], arr[i]) = (arr[i], arr[0])
				print('YES')
				print(' '.join([str(i) for i in arr]))
				tracker = True
				break
		if tracker == False:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if len(set(a)) == 1:
		print('NO')
	else:
		print('YES')
		sorted_list = sorted(a, reverse=True)
		if sorted_list[0] == sorted_list[1]:
			(sorted_list[-1], sorted_list[1]) = (sorted_list[1], sorted_list[-1])
		print(' '.join([str(i) for i in sorted_list]))


t = int(input())
for i in range(0, t):
	n = int(input())
	l1 = input()
	list1 = list(map(int, l1.split()))
	list1.sort(reverse=True)
	if list1[0] == list1[1]:
		if min(list1) == max(list1):
			print('NO')
		else:
			for i in range(2, n):
				if list1[i] != list1[1]:
					(list1[i], list1[1]) = (list1[1], list1[i])
					print('YES')
					print(' '.join(map(str, list1)))
					break
	else:
		print('YES')
		print(' '.join(map(str, list1)))


tc = int(input())
while tc:
	n = int(input())
	values = list(map(int, input().split(' ')))
	values.sort(reverse=True)
	n = len(values)
	solved = True
	for i in range(0, n):
		if values[0] != values[i]:
			solved = False
			break
	for i in range(0, n):
		if values[i] != values[0]:
			(values[i], values[0]) = (values[0], values[i])
			break
	if solved == False:
		print('YES')
		x = ' '.join([str(i) for i in values])
		print(x)
	else:
		print('NO')
	tc -= 1


tests = int(input())
for i in range(tests):
	length = int(input())
	reihe = sorted(list(map(int, input().split(' '))), reverse=True)
	if min(reihe) == max(reihe):
		print('NO')
	else:
		print('YES')
		reihe.insert(1, reihe[-1])
		reihe.pop()
		str_reihe = [str(i) for i in reihe]
		print(' '.join(str_reihe))


import heapq
import math
eps = 10 ** (-9)
from math import ceil, log

def solve():
	n = int(input())
	a = input().split(' ')
	a = [int(x) for x in a]
	if len(a) == 1:
		print('YES')
		print(str(a[0]))
		return
	if len(set(a)) == 1:
		print('NO')
		return
	a.sort()
	a = a[::-1]
	print('YES')
	i = 1
	res = str(a[0]) + ' ' + str(a[-1])
	while i < n - 1:
		res += ' ' + str(a[i])
		i += 1
	print(res)
	return
t = int(input())
for _ in range(t):
	solve()


numbers = []
summ = 0
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	max_num = max(a)
	min_num = min(a)
	index_max = a.index(max(a))
	index_min = a.index(min(a))
	if len(set(a)) == 1:
		bool = 'NO'
		print(bool)
		continue
	bool = 'YES'
	numbers.append(max_num)
	numbers.append(min_num)
	a.remove(max_num)
	a.remove(min_num)
	numbers.extend(a)
	if bool == 'YES':
		print(bool)
		print(' '.join([str(i) for i in numbers]))
	numbers = []
	summ = 0


def solve(var1, var2):
	allSame = True
	for item in var2:
		if var2[0] != item:
			allSame = False
	if allSame:
		return 'NO'
	if len(var2) == 1:
		return 'NO'
	ansTable = var2
	(ansTable[0], ansTable[len(ansTable) - 1]) = (ansTable[len(ansTable) - 1], ansTable[0])
	if ansTable[0] == 0:
		return 'NO'
	if ansTable[1] == ansTable[0]:
		(ansTable[1], ansTable[len(ansTable) - 1]) = (ansTable[len(ansTable) - 1], ansTable[1])
	return ansTable
testCount = int(input())
for i in range(testCount):
	var1 = int(input())
	var2 = input().split(' ')
	ans = solve(var1, var2)
	if ans != 'NO':
		print('YES')
		ansString = ''
		for item in ans:
			ansString += str(item) + ' '
		print(ansString.rstrip())
	else:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	sumy = 0
	ans = 'YES'
	for i in arr:
		if i == sumy:
			ans = 'NO'
			break
		else:
			sumy += i
	if ans == 'NO':
		arr.sort(reverse=True)
		if arr == [0]:
			ans = 'NO'
		elif arr[0] == arr[1]:
			for i in range(2, n):
				if arr[i] != 0 and arr[i] != arr[0]:
					(arr[i], arr[0]) = (arr[0], arr[i])
					ans = 'YES'
					break
		else:
			ans = 'YES'
	if ans == 'NO':
		print(ans)
	else:
		print(ans)
		print(' '.join([str(i) for i in arr]))


from typing import List

def solve(n, a: List[int]):
	a.reverse()
	if a[1] == a[0]:
		for i in range(2, n):
			if a[i] != a[1]:
				(a[i], a[1]) = (a[1], a[i])
				return a
		return []
	else:
		return a

def convert_a_to_str(a: List[int]):
	return ' '.join([str(num) for num in a])
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(num) for num in input().split(' ', n - 1)]
	ans = solve(n, a)
	if len(ans) > 0:
		print('YES')
		print(convert_a_to_str(a))
	else:
		print('NO')


import os

def main():
	user_input = []
	track = 0
	while True:
		if track == 0:
			numCases = input()
			user_input.append(numCases)
		elif track == int(numCases) * 2 + 1:
			break
		else:
			user_input.append(input())
		track += 1
	for i in range(1, int(numCases) * 2, 2):
		string = ''
		numLine = int(user_input[i])
		numbers = [int(x) for x in user_input[i + 1].split()]
		if check(numbers):
			print('YES')
			for j in numbers:
				string += f'{str(j)} '
			print(string)
		else:
			output = beautiful(numbers, numLine)
			if output is None:
				print('NO')
			else:
				print('YES')
				for j in output:
					string += f'{str(j)} '
				print(string)

def check(numbers):
	total = 0
	for i in numbers:
		if i == total:
			return False
		total += i
	return True

def beautiful(numbers, numLine):
	array = []
	numbers.sort()
	maximum = numbers[-1]
	minimum = numbers[0]
	if maximum != minimum:
		array.append(minimum)
		array.append(maximum)
		for i in range(1, numLine - 1, 1):
			array.append(numbers[i])
		return array
	else:
		return None
main()


def sol(a):
	ass = set(a)
	if len(ass) == 1:
		print('NO')
		return
	a = sorted(a, reverse=True)
	if a[0] == a[1]:
		(a[0], a[-1]) = (a[-1], a[0])
	print('YES')
	out = ''
	for i in a:
		out = out + str(i) + ' '
	out = out[:-1]
	print(out)
	return
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	sol(a)


number_cases = int(input())
for _ in range(number_cases):
	counter = 0
	ans = 'YES'
	list_len = int(input())
	mylist = list(map(int, input().split()))
	x = mylist
	x.sort()
	if x[0] == x[list_len - 1]:
		print('NO')
	else:
		ethan = []
		half_len = len(mylist) // 2
		mylist.sort()
		for n in range(0, half_len):
			ethan.append(mylist[n])
			ethan.append(mylist[list_len - n - 1])
		if list_len % 2 != 0:
			ethan.append(mylist[half_len])
		print('YES')
		print(' '.join(map(str, ethan)))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	mina = 101
	maxa = 0
	for j in range(n):
		x = a[j]
		if x > maxa:
			maxa = x
		if x < mina:
			mina = x
	if mina == maxa:
		print('NO')
	else:
		print('YES')
		a.remove(maxa)
		a.remove(mina)
		print(maxa, mina, ' '.join(list(map(str, a))))


import sys
for i in range(int(sys.stdin.readline())):
	l = int(sys.stdin.readline())
	ls = [int(a) for a in sys.stdin.readline().split()]
	if [ls[0]] * l == ls:
		print('NO')
		continue
	ls.sort()
	ls = ls[::-1]
	x = ls[0]
	if ls[0] == ls[1]:
		p = 1
		while x == ls[p]:
			p += 1
		ls[0] = ls[p]
		ls[p] = x
	for j in range(l):
		ls[j] = str(ls[j])
	print('YES')
	print(' '.join(ls))


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	arr.sort(reverse=True)
	prev = 0
	c = 0
	while c < n - 1 and arr[c] == arr[c + 1]:
		c += 1
	if c == n - 1:
		print('NO')
	else:
		arr = arr[c:] + arr[:c]
		print('YES')
		print(' '.join((str(x) for x in arr)))


tc = int(input())
for i in range(tc):
	n = int(input())
	lt = list(map(int, input().split()))
	lt = lt[::-1]
	temp = lt[-1]
	lt[-1] = lt[1]
	lt[1] = temp
	flag = True
	lst = lt[:]
	for j in range(1, n):
		if lst[j] == lst[j - 1]:
			flag = False
			break
		else:
			lst[j] += lst[j - 1]
	if flag:
		print('YES')
		print(' '.join(list(map(str, lt))))
	else:
		print('NO')


def print_f(lista: list):
	palabra = ''
	for elemento in lista:
		palabra += str(elemento) + ' '
	print(palabra[:-1])
cantidad = int(input())
for i in range(cantidad):
	n = int(input())
	lista_inicial = input().split(' ')
	lista = list(map(lambda x: int(x), lista_inicial))
	lista.sort(reverse=True)
	if len(lista) == 1:
		if lista[0] == 0:
			print('NO')
		else:
			print('YES')
			print_f(lista)
	elif lista[0] == lista[1]:
		if len(lista) <= 2:
			print('NO')
		elif lista[-1] == lista[0]:
			print('NO')
		else:
			a = lista[0]
			lista[0] = lista[-1]
			lista[-1] = a
			print('YES')
			print_f(lista)
	else:
		print('YES')
		print_f(lista)


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


t = int(input())
for _ in range(t):
	n = int(input())
	nums = sorted(list(map(int, input().split())), reverse=True)
	(lst1, lst2) = ([], [])
	for num in nums:
		if not lst1 or lst1[-1] != num:
			lst1.append(num)
		else:
			lst2.append(num)
	lst = lst1 + lst2
	if len(lst) > 1:
		if lst[0] == lst[1]:
			print('NO')
		else:
			print('YES')
			print(' '.join(list(map(str, lst))))
	else:
		print('YES')
		print(lst)


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(a, n):
	if len(set(a)) == 1:
		return []
	a = sorted(a)[::-1]
	return [a[0]] + [a[-1]] + a[1:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = solve(a, n)
	if not res:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, res)))


a = input()
for i in range(int(a)):
	n = int(input())
	L = [int(x) for x in input().split(' ')]
	L.sort(reverse=True)
	tag = 'NO'
	rem = None
	for num in L:
		if not rem:
			rem = num
		elif num != rem:
			print('YES')
			tag = 'YES'
			break
		else:
			rem = num
			tag = 'NO'
	if tag == 'NO':
		print('NO')
	else:
		t = 0
		for num in L:
			if num == L[0]:
				t += 1
			else:
				break
		newL = L[t - 1:] + L[:t - 1]
		print(' '.join([str(x) for x in newL]))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	counter = arr.count(arr[0])
	if counter == n:
		print('NO')
	else:
		arr.sort()
		ans = [0] * n
		(low, high) = (0, n - 1)
		ind = 0
		while low < high:
			ans[ind] = str(arr[low])
			ind += 1
			low += 1
			ans[ind] = str(arr[high])
			ind += 1
			high -= 1
		if low == high:
			ans[ind] = str(arr[low])
		print('YES')
		print(' '.join(ans))


for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	L = sorted(L)
	L1 = []
	i = 0
	j = n - 1
	for k in range(n):
		if k % 2 == 0:
			L1.append(L[i])
			i += 1
		else:
			L1.append(L[j])
			j -= 1
	s = L1[0]
	t = 0
	for i in range(1, n):
		if L1[i] == s:
			print('NO')
			t = 1
			break
		s += L1[i]
	if t != 1:
		print('YES')
		print(' '.join(map(str, L1)))


for s in [*open(0)][2::2]:
	(*a, l) = s.split()
	print(*(['NO'], ['YES\n', l] + a)[l != a[0]])