Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.

- Select a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them.

Find out minimum sum of costs of operations needed to convert the array into a single element.

-----Input-----
First line of input contains a single integer T denoting the number of test cases. First line of each test case starts with an integer N denoting the size of the array A. Next line of input contains N space separated integers, where the ith integer denotes the value Ai.

-----Output-----
For each test case, print the minimum cost required for the transformation.

-----Constraints-----
- 1 ≤ T ≤ 10 
- 2 ≤ N ≤ 50000 
- 1 ≤ Ai ≤ 105 

-----Subtasks-----
- Subtask 1 : 2 ≤ N ≤ 15 : 35 pts 
- Subtask 2 : 2 ≤ N ≤ 100 : 25 pts 
- Subtask 3 : 2 ≤ N ≤ 50000 : 40 pts 

-----Example-----
Input
2
2
3 4
3
4 2 5

Output
3
4

-----Explanation-----Test 1 :  Chef will make only 1 move: pick up both the elements (that is, 3 and 4), remove the larger one (4), incurring a cost equal to the smaller one (3).

Difficulty: interview

Starter code:

Solutions:
from math import *
for t in range(int(input())):
 n = int(input())
 numberlist = list(map(int,input().split()))
 numberlist.sort()
 print(numberlist[0]* ( len(numberlist) -1))

t=int(input())
for i in range(t):
 n=int(input())
 a=list(map(int,input().split()))
 a.sort()
 m=a[0]
 ans=(len(a)-1)*m
 print(ans)


# cook your dish here
try:
 test_case = int(input())
 for i in range(test_case):
  user = int(input())
  
  array = sorted(list(map(int,input().split())) , reverse=True)[:user]
  c = array[len(array)-1]
  array.remove(array[0])
  b = len(array)*c
  print(b)
except:
 pass

T = int(input())
for i in range(T):
 N = int(input()) 
 a = sorted(list(map(int,input().split())) , reverse=True)
 c = a[len(a)-1]
 a.remove(a[0])
 b = len(a)*c
 print(b) 

# cook your dish here
try:
 T = int(input())
 for i in range(T):
  N = int(input())
  
  a = sorted(list(map(int,input().split())) , reverse=True)[:N]
  c = a[len(a)-1]
  a.remove(a[0])
  b = len(a)*c
  print(b)
  #  ans=(len(a)-1)*m
except:
 pass

t=int(input())
for i in range(t):
 n=int(input())
 a=list(map(int,input().split()))
 a.sort()
 m=a[0]
 ans=(len(a)-1)*m
 print(ans)


t=int(input())
for i in range(t):
 n=int(input())
 a=list(map(int,input().split()))
 a.sort()
 s=0
 while(len(a)>1):
   a.remove(a[1])
   s=s+a[0]
 print(s)
 


t=int(input())
for i in range(t):
 n=int(input())
 a=list(map(int,input().split()))
 a.sort()
 s=0
 while(len(a)!=1):
   a.remove(a[1])
   s=s+a[0]
 print(s)
 


t=int(input())
for i in range(t):
 n=int(input())
 a=list(map(int,input().split()))
 a.sort()
 s=0
 while(True):
  if(len(a)==1):
   break
  else:
   a.remove(a[1])
   s=s+a[0]
 print(s)
 


N = int(input())
for i in range(N):
 a=int(input())
 li=[int(x) for x in input().split()]
 a=min(li)
 print(a*(len(li)-1))

t=int(input())
for w in range(t):
 n=int(input())
 l=list(map(int,input().split()))
 cost=min(l)
 length=len(l)
 print(cost*(length-1))

# cook your dish here
t=int(input())
for w in range(t):
 n=int(input())
 l=list(map(int,input().split()))
 cost=min(l)
 length=len(l)
 print(cost*(length-1))

for i in range(int(input())):
 n1=int(input())
 a=list(map(int,input().split()))
 m=min(a)
 print(m*(n1-1))


# cook your dish here
for i in range(int(input())):
 n=int(input())
 lis=list(map(int,input().split()))
 print(min(lis)*(n-1))

# cook your dish here
for i in range(int(input())):
 n=int(input())
 lis=list(map(int,input().split()))
 print(min(lis)*(n-1))

for _ in range(int(input())):
 n=int(input())
 a=list(map(int,input().split()))
 m=min(a)
 print(m*(n-1))


# cook your dish here

T=int(input())

for _ in range(T):
  
 n=int(input())
 x=list(map(int,input().split()))
  
 print(min(x)*(n-1))
  


import re

class arrSol():
 def __init__(self):
  self.N = 0
  self.arr = 0
 
 def updateN(self, N):
  self.N = N

 def populateArr(self):
  self.arr = input()
  self.arr = re.split(" ", self.arr)
  
 def findCost(self):
  min = 100001
  for i in range(self.N):
   if int(self.arr[i]) < min:
    min = int(self.arr[i])
  return min * (self.N - 1) 
  
  
  


T = int(input())

for i in range(T):
 
 myObj = arrSol()
 myObj.updateN(int(input()))
 myObj.populateArr()
 print(int(myObj.findCost()))
 del myObj
 


# cook your dish here
a = int(input())
for i in range(0,a):
 n = int(input())
 x = list(map(int, input().split()))
 print(min(x) * (n-1))

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 a=[int(x) for x in input().split()]
 m=min(a)
 print(m*(n-1))

t=int(input())
for i in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 print(min(lst)* (n-1))


# cook your dish here
t = int(input())
for i in range(0,t):
 n = int(input())
 a = list(map(int, input().split()))
 print(min(a) * (n-1))

# cook your dish here
t = int(input())

for i in range(t):
 n = int(input())

 array = list(map(int, input().split()))

 minEle = min(array)
 print(minEle * (n - 1))


# cook your dish here
t=int(input())
for m in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 print(min(lst)*(n-1))



# cook your dish here
t = int(input())

for i in range(t):
 n = int(input())

 array = list(map(int, input().split()))

 minEle = min(array)
 print(minEle * (n - 1))