Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, 
B potions of blue liquid, and G potions of green liquid.

- 
The red liquid potions have liquid amounts given by r[1], ..., r[R] liters. 

- 
The green liquid potions have liquid amounts given by g[1], ..., g[G] liters. 

- 
The blue liquid potions have liquid amounts given by b[1], ..., b[B] liters. 

She want to play with the potions by applying magic tricks on them. In a single magic trick, she will choose a particular color. Then she will pick all the potions of the chosen color and decrease the amount of liquid in them to half (i.e. if initial amount 
of liquid is x, then the amount after decrement will be x / 2  where division is integer division, e.g. 3 / 2 = 1 and 4 / 2 = 2). 

Because she has to go out of station to meet her uncle Churu, a wannabe wizard, only M minutes are left for her. In a single minute, she can perform at most one magic trick. Hence, she can perform at most M magic tricks.

She would like to minimize the maximum amount of liquid among all of Red, Green and Blue colored potions. Formally Let v be the maximum value of amount of liquid in any potion. We want to minimize the value of v.
Please help her.

-----Input-----

First line of the input contains an integer T denoting the number of test cases.
Then for each test case, we have four lines.

The first line contains four space separated integers R, G, B, M. The next 3 lines will describe the amount of different color liquids (r, g, b), which are separated by space.

-----Output-----
For each test case, print a single integer denoting the answer of the problem.

-----Constraints-----
-  1 ≤ T ≤ 1000 
-  1 ≤ R, G, B, M ≤ 100 
-  1 ≤ r[i], g[i], b[i] ≤ 10^9 

-----Example-----
Input:
3
1 1 1 1
1
2
3
1 1 1 1
2
4
6
3 2 2 2
1 2 3
2 4
6 8
Output:
2
4
4

-----Explanation-----
Example case 1. Magical girl can pick the blue potion and make its liquid amount half. So the potions will now have amounts 1 2 1. Maximum of these values is 2. Hence answer is 2.

Difficulty: interview

Starter code:

Solutions:
import sys
import math
import heapq
def half(n):
 return n//2
def main(arr,m):
 a,b,c=arr
 
 while m!=0:
  
  
  
  s=max(a,b,c)
  
  if s==a:
   a=half(a)
  elif s==b:
   b=half(b)
  else:
   c=half(c)
  m-=1
 return max(a,b,c)
   
 
 
 
 

for i in range(int(input())):
 r,g,b,m=list(map(int,input().split()))
 arr=[]
 for j in range(3):
  c=max(list(map(int,input().split())))
  arr.append(c)
 
 print(main(arr,m))


import sys
import math
import heapq
def half(arr):
 for i in range(len(arr)):
  arr[i]//=2
 return arr
def main(arr,m):
 x,y,z=arr
 x.sort()
 y.sort()
 z.sort()
 
 while m!=0:
  
  a,b,c=x[-1],y[-1],z[-1]
  
  s=max(a,b,c)
  
  if s==a:
   half(x)
  elif s==b:
   half(y)
  else:
   half(z)
  m-=1
 return max(x[-1],y[-1],z[-1])
   
 
 
 
 

for i in range(int(input())):
 r,g,b,m=list(map(int,input().split()))
 arr=[]
 for j in range(3):
  c=list(map(int,input().split()))
  arr.append(c)
 
 print(main(arr,m))


# cook your dish here
for _ in range(int(input())):
 r,g,b,m=list(map(int, input().split()))
 l=[]
 for i in range(3):
  l1=list(map(int, input().split()))
  l.append(l1)
   
 for i in range(m+1):
  a=0
  b=0
  for j in range(3):
   m=max(l[j])
   if m>a:
    a=m 
    b=j 
    
  for k in range(len(l[b])):
   l[b][k]=l[b][k]//2
    
 print(a)

def potion(m, l):
 for _ in range(m):
  l.sort()
  l[2] = l[2] // 2
 return max(l)

try:
 tstc = int(input())
 for t in range(tstc):
  r, g, b, m = map(int, input().split())
  red = [int(i) for i in input().split()]
  green = [int(i) for i in input().split()]
  blue = [int(i) for i in input().split()]
  print(potion(m, [max(red), max(green), max(blue)]))
except:
 pass

# cook your dish here
test=int(input())
for _ in range(test):
 r,b,g,m=map(int,input().split())
 red=sorted(map(int,input().split()),reverse=True)
 blue=sorted(map(int,input().split()),reverse=True)
 green=sorted(map(int,input().split()),reverse=True)
 x,y,z=red[0],blue[0],green[0]
 for _ in range(m):
  k=max(x,y,z)
  if k==x:
   x=x//2
  elif k==y:
   y=y//2
  else:
   z=z//2
 print(max(x,y,z))

# cook your dish here
for _ in range(int(input())):
 
 r,b,g,m = list(map(int,input().split()))
 
 red = sorted(map(int,input().split()),reverse=True)
 blue = sorted(map(int,input().split()),reverse=True)
 green = sorted(map(int,input().split()),reverse=True)
 x,y,z=red[0],blue[0],green[0]
 for _ in range(m):
  
  k=max(x,y,z)
  
  if k==x:
   x=x//2
   
  elif k==y:
   y=y//2
   
  else:
   z=z//2
  
 print(max(x,y,z))
   
 


t=int(input())
while(t>0):
 r,g,q,m=map(int,input().split())
 a=list(map(int,input().split()))
 b=list(map(int,input().split()))
 c=list(map(int,input().split()))
 for i in range(m):
  x=max(a)
  y=max(b)
  z=max(c)
  if(x>=y)and(x>=z):
   for j in range(r):
    a[j]//=2
  elif(y>=x)and(y>=z):
   for j in range(g):
    b[j]//=2
  else:
   for j in range(q):
    c[j]//=2
 x=max(a)
 y=max(b)
 z=max(c)
 print(max(x,max(y,z)))
 t-=1

for _ in range(int(input())):
 r1,g1,b1,m=map(int,input().split())
 r=[int(i) for i in input().split()]
 g=[int(j) for j in input().split()]
 b=[int(k) for k in input().split()]
 while m>0:
  if max(max(r),max(g),max(b)) in r:
   r=[i//2 for i in r]
  elif max(max(r),max(g),max(b)) in g:
   g=[j//2 for j in g]
  else:
   b=[k//2 for k in b]
  m-=1
 print(max(max(r),max(g),max(b)))

t = int(input()) 
for i in range (t) :
 line = input()
 pui = line.split()
 r = int(pui[0])
 g = int(pui[1]) 
 b = int(pui[2]) 
 m = int(pui[3]) 
 ar = list()
 for i in range (3) :
  line = input()
  pui = line.split()
  pui = [int (j) for j in pui]
  ar.append(pui) 
 for i in range (m) :
  R = max(ar[0]) 
  G = max(ar[1]) 
  B = max(ar[2]) 
  if R>=G and R >= B :
   for j in range(len(ar[0]))  :
    ar[0][j] = int(ar[0][j] / 2) 
  elif G >= R and G >= B :
   for j in range(len(ar[1])) : 
    ar[1][j] = int(ar[1][j] / 2) 
  elif B >= G and B >= R :
   for j in range(len(ar[2])) : 
    ar[2][j] = int(ar[2][j] / 2)
 R = max(ar[0]) 
 G = max(ar[1]) 
 B = max(ar[2])
 ans = max(R, G, B)
 print(ans)


t = int(input()) 
for i in range (t) :
 line = input()
 pui = line.split()
 r = int(pui[0])
 g = int(pui[1]) 
 b = int(pui[2]) 
 m = int(pui[3]) 
 ar = list()
 for i in range (3) :
  line = input()
  pui = line.split()
  pui = [int (j) for j in pui]
  ar.append(pui) 
 for i in range (m) :
  R = max(ar[0]) 
  G = max(ar[1]) 
  B = max(ar[2]) 
  if R>=G and R >= B :
   for j in range(len(ar[0]))  :
    ar[0][j] = int(ar[0][j] / 2) 
  elif G >= R and G >= B :
   for j in range(len(ar[1])) : 
    ar[1][j] = int(ar[1][j] / 2) 
  elif B >= G and B >= R :
   for j in range(len(ar[2])) : 
    ar[2][j] = int(ar[2][j] / 2)
 R = max(ar[0]) 
 G = max(ar[1]) 
 B = max(ar[2])
 ans = max(R, G, B)
 print(ans)


for _ in range(int(input())):
 R,G,B,M=map(int,input().split())
 l=[]
 r=list(map(int,input().split()))
 rm=max(r)
 g=list(map(int,input().split()))
 gm=max(g)
 b=list(map(int,input().split()))
 bm=max(b)
 l=[rm,gm,bm]
 l.sort()
 for i in range(M):
  l[-1]//=2
  l.sort()
 print(l[-1])

for j in range(int(input())):
 r,g,b,m=map(int,input().split())
 x=[]
 for i in range(3):
  a=list(map(int,input().split()))
  x.append(a)
 while(m!=0):
  c=[]
  for i in x:
   c.append(max(i))
  z=c.index(max(c))
  for i in range(len(x[z])):
   x[z][i]=x[z][i]//2
  m-=1
 am=[]
 for i in x:
  am+=i
 print(max(am))

T = int(input())
for i in range(T):
 [r, g, b, k] = list(map(int, input().split()))
 s = list(map(int,input().split()))
 t = list(map(int,input().split()))
 c = list(map(int,input().split()))
 j = sorted([max(s),max(t),max(c)])
 for i in range(k):
  j[-1] = int(j[-1] / 2)
  j = sorted(j)
 print(j[-1])

for _ in range(int(input())):
 R, G, B, M = map(int, input().split())
 R_list = list(map(int, input().split()))
 G_list = list(map(int, input().split()))
 B_list = list(map(int, input().split()))
 for j in range(M):
  rSum = max(R_list)
  gSum = max(G_list)
  bSum = max(B_list)
  p = max(rSum, bSum, gSum)
  if p == rSum:
   for i in range(R):
    R_list[i] = R_list[i] // 2
  elif p == bSum:
   for i in range(B):
    B_list[i] = B_list[i] // 2
  else:
   for i in range(G):
    G_list[i] = G_list[i] // 2
 rSum = max(R_list)
 gSum = max(G_list)
 bSum = max(B_list)
 print(max(rSum, bSum, gSum))

# cook your dish here
t=int(input())
for i in range(t):
 [r,g,b,k]=list(map(int,input().split()))
 rs=list(map(int,input().split()))
 bs=list(map(int,input().split()))
 gs=list(map(int,input().split()))
 ans=sorted([max(rs),max(bs),max(gs)])
 for i in range(k):
  ans[-1]=int(ans[-1]/2)
  ans=sorted(ans)
 print(ans[-1])

t=int(input())
for x in range(0,t):
 r,g,b,m=map(int,input().split())
 a=[]
 c=[]
 for i in range(0,3):
  v=list(map(int,input().split()))
  v.sort(reverse=True)
  a.append(v)
 a.sort() 
 for i in range(0,m):
  l=len(a[2])
  j=0
  while(j<l):
   a[2][j]=int(a[2][j]/2)
   j+=1
  a.sort() 
 for x in a:
  c.append(max(x))
 print(max(c)) 

# cook your dish here
for _ in range(int(input())):
 r,g,b,m=list(map(int,input().split()))
 r=list(map(int,input().split()))
 g=list(map(int,input().split()))
 b=list(map(int,input().split()))
 x=max(r)
 y=max(g)
 z=max(b)
 while m>0:
  if x>=y and x>=z:
   x//=2
  elif y>=x and y>=z:
   y//=2
  else:
   z//=2
  m-=1
 print(max(x,y,z))


t=int(input())

for _ in range(t):
 R, G, B, M = [int(x) for x in input().split(' ')]
 r = [int(x) for x in input().split(' ')]
 g = [int(x) for x in input().split(' ')]
 b = [int(x) for x in input().split(' ')]
 r.sort(reverse=True)
 g.sort(reverse=True)
 b.sort(reverse=True)
 
 for y in range(M):
  m = max(r[0], g[0], b[0])
  if m == r[0]:
   r = [x//2 for x in r]
  elif m == g[0]:
   g = [x//2 for x in g]
  elif m == b[0]:
   b = [x//2 for x in b]
 
 print(max(r[0], g[0], b[0]))
 


for _ in range(int(input())):
 r, g, b, m = map(int, input().split())
 R = max(list(map(int, input().split())))
 G = max(list(map(int, input().split())))
 B = max(list(map(int, input().split())))
 
 cur = [R, G, B]
 
 while m > 0:
  m -= 1
  index = cur.index(max(cur))
  cur[index] //= 2
 
 print(max(cur))

t=int(input())
for ijk in range(0,t):
 r,g,b,m=list(map(int,input().strip().split()))
 ra=list(map(int,input().strip().split()))
 rb=list(map(int,input().strip().split()))
 rc=list(map(int,input().strip().split()))
 a=[max(ra),max(rb),max(rc)]
 for i in range(0,m):
  j=a.index(max(a))
  a[j]=a[j]//2
 print(max(a))
  
 


for _ in range(int(input())):
 
 r,g,b,m = map(int, input().split())
 Rarr = list(map(int, input().split()))
 Garr = list(map(int, input().split()))
 Barr = list(map(int, input().split()))
 while(m > 0):
  Rmax = max(Rarr)
  Gmax = max(Garr)
  Bmax = max(Barr)
  if Rmax == max(Gmax, Rmax, Bmax):
   Rarr = [int(i/2) for i in Rarr]
  elif Gmax == max(Gmax, Rmax, Bmax):
   Garr = [int(i/2) for i in Garr]
  else:
   Barr = [int(i/2) for i in Barr]
  m-=1
 total = Rarr + Garr + Barr
 total.sort()
 print(total[-1])