Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order.
Ada has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ minutes, removes it from this burner; the dish may not be removed from the burner before those $C_i$ minutes pass, because otherwise it cools down and gets spoiled. Any two dishes may be prepared simultaneously, however, no two dishes may be on the same burner at the same time. Ada may remove a dish from a burner and put another dish on the same burner at the same time.
What is the minimum time needed to prepare all dishes, i.e. reach the state where all dishes are prepared?

-----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 $C_1, C_2, \ldots, C_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum number of minutes needed to prepare all dishes.

-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 4$
- $1 \le C_i \le 5$ for each valid $i$

-----Subtasks-----
Subtask #1 (1 points): $C_1 = C_2 = \ldots = C_N$
Subtask #2 (99 points): original constraints

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

-----Example Output-----
4
3
7

-----Explanation-----
Example case 1: Place the first two dishes on the burners, wait for two minutes, remove both dishes and prepare the last one on one burner.
Example case 2: Place the first and third dish on the burners. When the first dish is prepared, remove it and put the second dish on the same burner.
Example case 3: Place the third and fourth dish on the burners. When the third dish is prepared, remove it and put the second dish on the same burner. Similarly, replace the fourth dish (when it is prepared) by the first dish on the other burner.

Starter code:

Solutions:
for i in range(int(input())):
 n=int(input())
 c=[int(z) for z in input().split()]
 c.sort()
 c.reverse()
 b1,b2=0,0
 for i in range(n):
  if b1<b2:
   b1+=c[i]
  elif b2<b1:
   b2+=c[i]
  else:
   b1+=c[i]
 print(max(b1,b2))
   


n=int(input())
for i in range(n):
 N=int(input())
 lst=list(map(int,input().split()))
 lst.sort()
 if N==1:
  print(lst[0])
 elif N==2:
  print(lst[1])
 elif N==3:
  print(lst[1]+max(lst[0],(lst[2]-lst[1])))
 else:
  if lst[3]-lst[2]>=lst[1]:
   print(lst[2]+lst[1]+max(lst[0],lst[3]-(lst[1]+lst[2])))
  else:
   print(lst[3]+max(lst[0],lst[1]+lst[2]-lst[3]))

   
   


# cook your dish here
n=int(input())
for i in range(n):
 N=int(input())
 lst=list(map(int,input().split()))
 if N==1:
  print(lst[0])
 elif N==2:
  print(lst[1])
 elif N==3:
  print(lst[1]+max(lst[0],(lst[2]-lst[1])))
 else:
  if lst[3]-lst[2]>=lst[1]:
   print(lst[2]+lst[1]+max(lst[0],lst[3]-(lst[1]+lst[2])))
  else:
   print(lst[3]+max(lst[0],lst[1]+lst[2]-lst[3]))


for _ in range(int(input())):
 a=int(input())
 b=list(map(int,input().split()))[:a]
 b.sort(reverse=True)
 n1,n2=0,0
 for i in range(a):
  if n1<n2:
   n1+=b[i]
  else:
   n2+=b[i]
 print(max(n1,n2))


# cook your dish here
t=int(input())
for i in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 lst.sort()
 if n==1:
  print(lst[0])
 elif n==2:
  print(lst[1])
 elif n==3:
  if lst[0]+lst[1]<=lst[2]:
   print(lst[2])
  else:
   print(lst[0]+lst[1])
 elif n==4:
  if lst[3]>=lst[1]+lst[0]+lst[2]:
   print(lst[3])
  else:
   if lst[0]==lst[1]==lst[2]==lst[3]:
    print(2*lst[0])
   else:
    print(lst[3]+max(lst[0],(lst[1]-lst[3]+lst[2])))
   
   
  


# cook your dish here
t=int(input())
for i in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 lst.sort()
 if n==1:
  print(lst[0])
 elif n==2:
  print(lst[1])
 elif n==3:
  if lst[0]+lst[1]<=lst[2]:
   print(lst[2])
  else:
   print(lst[0]+lst[1])
 elif n==4:
  if lst[3]>=lst[1]+lst[0]+lst[2]:
   print(lst[3])
  else:
   if lst[0]==lst[1]==lst[2]==lst[3]:
    print(2*lst[0])
   else:
    print(lst[0]+lst[1]+lst[2])
   
   
  


# cook your dish here
t=int(input())
for i in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 lst.sort()
 if n==1:
  print(lst[0])
 elif n==2:
  print(lst[1])
 elif n==3:
  print(lst[0]+lst[2])
 elif n==4:
  print(max((lst[0]+lst[3]),(lst[1]+lst[2])))


# cook your dish here
t=int(input())
for i in range(t):
 n=int(input())
 lst=list(map(int,input().split()))
 lst.sort()
 if n==1:
  print(lst[0])
 elif n==2:
  print(lst[1])
 elif n==3:
  print(lst[0]+lst[2])
 else:
  print(max((lst[0]+lst[3]),(lst[1]+lst[2])))


# cook your dish here
t=int(input())
for _ in range(t):
 a=int(input())
 l=list(map(int,input().split()))
 l1=sorted(l)
 if len(l)==1:
  print(l[0])
 elif len(l)==2:
  print(max(l1[1],l1[0]))
 else:
  x=0
  k=l1[0]+l1[1]
  for i in range(2,len(l1)):
   x=x+(l1[i]-l1[i-1])
  print(k+x)
  
  


t=int(input(""))
for _ in range(t):
 n=int(input(""))
 l=list(map(int,input("").strip().split()))[:n]
 l.sort(reverse=True)
 b1=b2=0
 for i in l:
   if b1<b2:
    b1+=i
   else:
    b2+=i
 print(max(b1,b2))

t=int(input())
while t:
 n=int(input())
 dish=list(map(int,input().split()))
 b0,b1=0,0 
 mins=0 
 dish.sort(reverse=True)
 for i in dish:
  if b0<=b1:
   b0=b0+i
  else:
   b1=b1+i
 print(max(b0,b1))
 t-=1

t=int(input())
while t:
 n=int(input())
 dish=list(map(int,input().split()))
 b0,b1=0,0 
 mins=0 
 dish.sort(reverse=True)
 for i in dish:
  if b0<=b1:
   b0=b0+i
  else:
   b1=b1+i
 print(max(b0,b1))
 t-=1

def main():
 t=int(input())
 while(t):
  n=int(input())
  list1=list(map(int,input().split()))
  list1.sort(reverse=True)
  b0=0
  b1=0
  for i in list1:
   if b0<=b1:
    b0+=i
   else:
    b1+=i
  print(max(b0,b1))
  t=t-1
  
main()


t=int(input())
while t:
 n=int(input())
 dish=list(map(int,input().split()))
 b0,b1=0,0 
 mins=0 
 dish.sort(reverse=True)
 for i in dish:
  if b0<=b1:
   b0=b0+i
  else:
   b1=b1+i
 print(max(b0,b1))
 t-=1

try:
 t=int(input())
 for _ in range(t):
   c=0
   n=int(input())
   a=list(map(int,input().split()))
   a.sort(reverse=True)

   b=c=0
   for i in a:
    if(b<c):
      b+=i
    else:
      c+=i
   print(max(b,c))

except:
 pass


for t in range(int(input())):
  
  n=int(input())
  a=list(map(int,input().split()))
  a.sort(reverse=True)
  b=c=0
  for i in a:
   if(b<c):
     b+=i
   else:
     c+=i
  print(max(b,c))

# cook your dish here
for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  a.sort()
  if(n==1):
   print(a[0])
  elif(n==2):
   print(max(a[0],a[1]))
  else:
   b=a[n-1]
   c=a[n-2]
   for i in range(n-3,-1,-1):
     if(c<b):
      c+=a[i]
     else:
      b+=a[i]
   if(c<b):
     print(b)
   else:
     print(c)


# cook your dish here
t=int(input())
for _ in range(t):
  c=0
  n=int(input())
  a=list(map(int,input().split()))
  a.sort(reverse=True)
  b=c=0
  for i in a:
   if(b<c):
     b+=i
   else:
     c+=i
  print(max(b,c))

# cook your dish here
try: 
 t = int(input())
except:
 t = 0
for i in range(t):
 n = int(input())
 l = list(map(int,input().split()))
 l.sort(reverse=True)
 b1=b2=0
 for i in l:
  if(b1<b2):
   b1+=i
  else:
   b2+=i
 print(max(b1,b2))

# cook your dish here
for i in range(int(input())):
 n=int(input())
 l=list(map(int,input().split()))
 l.sort()
 len1=len(l)
 a=l[len1-1]
 b=l[len1-2]
 len1-=2
 sum=0
 c=0
 for j in range(n-1):
  if l[j]!=l[j+1]:
   c=1
 if c==0:
  if n%2!=0:
   n=(n//2)+1
   print(n*l[0])
  else:
   n=n//2
   print(n*l[0])
 else:
  while(len1>=0):
   if len1==0:
    z=max(a,b)
    sum+=z
    break
   else:
    z=min(a,b)
   sum+=z
   len1-=1
   if a<b:
    a=l[len1]
    b=b-z
   else:
    b=l[len1]
    a=a-z
  print(sum)
    
   
  


# cook your dish here
# cook your dish here
for i in range(int(input())):
 N=int(input())
 C=list(map(int,input().split()))
 C.sort(reverse=True)
 b1=b2=0
 for i in range(N):
  if b1<b2:
   b1+=C[i]
  else:
   b2+=C[i]
 print(max(b1,b2))

t = int(input())
output = []

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

 c = list(map(int, input().split()))
 c.sort(reverse=True)

 burner1 = 0
 burner2 = 0

 for x in range(n):
  if burner1 < burner2:
   burner1 += c[x]
  else:
   burner2 += c[x]

 output.append(str(max(burner1,burner2)))

print('\n'.join(output))

def get_mini(n, ls):
 ls = sorted(ls)[::-1]
 first_burner = 0
 second_burner = 0
 for i in range(n):
  if first_burner <= second_burner:
   first_burner += ls[i]
  else:
   second_burner += ls[i]
 return max(first_burner, second_burner)


t = int(input())
for _ in range(t):
 n = int(input())
 dish = list(map(int, input().split()))
 ans = get_mini(n, dish)
 print(ans)

# cook your dish here
for i in range(int(input())):
 N=int(input())
 C=list(map(int,input().split()))
 C.sort(reverse=True)
 b1=b2=0
 for i in range(N):
  if b1<b2:
   b1+=C[i]
  else:
   b2+=C[i]
 print(max(b1,b2))

t = int(input())
d = []
for i in range(t):
 n = int(input())
 d.append(list(map(int, input().split())))

output = []
for arr in d:
 arr.sort(reverse=True)
 time = 0
 i = 0
 t = 0
 while i < len(arr):
  if t == 0:
   time += arr[i]
   t = arr[i]
  i += 1
  if i >= len(arr):
   break
  if arr[i] <= t:
   t -= arr[i]
   arr[i] = 0
  else:
   arr[i] -= t
   t = 0
 output.append(time)

for i in output:
 print(i)