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

Difficulty: interview

Starter code:

Solutions:
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")
 
# cook your dish here


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)

# cook your dish here
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 list(g.items()) if count>=3]
  if h:
   print("NO")
  elif g[arr[-1]]==2:
   print("NO")
  else:
   k = [item for item,count in list(g.items()) if count==2]
   k = sorted(k, reverse = True)
   seti.extend(k)
   print("YES")
   print(*seti)


# cook your dish here
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") 


# cook your dish here
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)
  

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

  


# cook your dish here
def solve(n, lst):
 d = dict()

 p1 = []
 p2 = []
 for i in lst:
  if i in list(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)))


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)

# cook your dish here
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

# cook your dish here
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]
  else:
   if 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]
 # print(ans)
 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()

# cook your dish here
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

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)

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)

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)

# cook your dish here
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")
   



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


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
 #print(lis)
 lis.sort(reverse=True)
 #print(lis)
 d=a+lis
 print("YES")
 for i in d:
  print(i,end=" ")
 print()
 return


t=int(input())
while(t>0):
 ans()
 t-=1




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)
  


# cook your dish here
def PrintBothArrays(a, n) : 
 
 # Store both arrays  
 v1, v2 = [], [] 
 
 # Used for hashing  
 mpp = dict.fromkeys(a, 0) 
 
 # Iterate for every element  
 for i in range(n) : 
 
  # Increase the count  
  mpp[a[i]] += 1 
 
  # If first occurrence  
  if (mpp[a[i]] == 1) : 
   v1.append(a[i]) 
 
  # If second occurrence  
  elif (mpp[a[i]] == 2) :  
   v2.append(a[i]) 
 
  # If occurs more than 2 times  
  else :  
   print("NO") 
   return;  
 
 # Sort in increasing order
 maximum=max(v1)
 if maximum in v2:
  print("NO")
  return;
 
 v1.sort();  
 
 # Print the increasing array  
 print("YES");  
 for it in v1: 
  print(it, end = " ");  
 
 # Sort in reverse order  
 v2.sort(reverse = True);  
 
 # Print the decreasing array 
 for it in v2 :  
  print(it, end = " ") 
 print()
 
# Driver code  
def __starting_point(): 
 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
__starting_point()

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) 
  else:
   if 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")
  
 
 
 
 
 
 
 
 
 
 



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
  else:
   if 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")
  
 
 
 
 
 
 
 



# cook your dish here
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())
 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")


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