rahul-bday

Rahulis planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Darshit: one is black and the other is white. To make her happy, Darshit has to buy B number of black gifts and W number of white gifts.

The cost of each black gift is X units.

The cost of every white gift is Y units.

The cost of converting each black gift into white gift or vice versa is Z units.

Help Darshit by deducing the minimum amount he needs to spend on Diksha's gifts.

INPUT

The first line will contain an integer T which will be the number of test cases.
There will be T pairs of lines. The first line of each test case will contain the values of integers B and W. Another line of each test case will contain the values of integers X, Y, and Z.

OUTPUT

T lines, each containing an integer: the minimum amount of units Darshit needs to spend on gifts.

Constraints

1≤T≤10

0≤X,Y,Z,B,W≤109

SAMPLE INPUT
5
10 10
1 1 1
5 9
2 3 4
3 6
9 1 1
7 7
4 2 1
3 3
1 9 2

SAMPLE OUTPUT
20
37
12
35
12

Explanation

SAMPLE CASE 1:

There is no benefit to converting the white gifts into black or the black gifts into white, so Darshit will have to buy each gift for 1 unit. So cost of buying all gifts will be: 10∗1+10∗1=20. 

SAMPLE CASE 2:

Again, we can't decrease the cost of black or white gifts by converting colors. We will buy gifts at their original price. So cost of buying all gifts will be: 5∗2+9∗3=10+27=37. 

SAMPLE CASE 3:

We will buy white gifts at their original price, 1. For black gifts, we will first buy white one and color them to black, so that their cost will be reduced to 1+1=2. So cost of buying all gifts will be: 3∗2+6∗1=12.

SAMPLE CASE 4:

Similarly, we will buy white gifts at their original price, 2. For black gifts, we will first buy white one and color them to black, so that their cost will be reduced to 2+1=3. So cost of buying all gifts will be: 7∗3+7∗2=35.

SAMPLE CASE 5:

We will buy black gifts at their original price, 1. For white gifts, we will first black gifts worth 1 unit and color them to white with another 2 units, so cost for white gifts is reduced to 3 units. So cost of buying all gifts will be: 3∗1+3∗3=3+9=12.

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
T = eval(input())
for t in range(0,T):
	B,W = list(map(int,input().split()))
	X,Y,Z = list(map(int, input().split()))
	total=0
	if(X<Y):
		total = total + X*B
		if(X+Z < Y): total = total + (X+Z)*W
		else: total = total + Y*W
	else :
		total = total + Y*W
		if(Y+Z < X): total = total + (Y+Z)*B
		else: total = total + X*B
	print(total)


t=int(input())
while t>0:
	t=t-1
	gifts=list(map(int, input().split()))
	b=gifts[0]
	w=gifts[1]
	costs=list(map(int,input().split()))
	x=costs[0]
	y=costs[1]
	z=costs[2]
	tot=0
	if x<y:
		tot=tot+b*x
		if y>(x+z):
			tot=tot+(x+z)*w
		else:
			tot=tot+y*w
	else:
		tot=tot+w*y
		if x>(y+z):
			tot=tot+(y+z)*b
		else:
			tot=tot+x*b
	print(tot)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(eval(input()))

while t>0:
	line = input().split(" ")
	b = int(line[0])
	w = int(line[1])
	line = input().split(" ")
	x = int(line[0])
	y = int(line[1])
	z = int(line[2])
	
	if y+z<x:
		ans = b*(y+z)+y*w
	elif x+z<y:
		ans = w*(x+z)+x*b
	else: 
		ans = b*x+w*y
	print(ans)
	t=t-1
	


for _ in range(int(input())):
	b,w= list(map(int,input().split()))
	x,y,z=list(map(int,input().split()))
	if x==y:
		print((b+w)*x)
	else:
		val=min(x,y)
		if x==val:
			z1=y
			z2=x
		else:
			z1=x
			z2=y
		if x==val:
			val1=b
			val2=w
		else:
			val1=w
			val2=b
		print(val1*val+min(val2*z1, val2*(z2+z)))


for t in range(eval(input())):
	gifts=list(map(int,input().split(" ")))
	price=list(map(int,input().split(" ")))
	a=price[0]
	b=price[1]
	c=price[2]
	q=0
	w=0
	r=0
	if(a<c and b<c):
		q=1
	elif(a+c<b):
		w=1
	elif(b+c<a):
		r=1
	else:
		q=1
	if(q==1):
		total=gifts[0]*a+gifts[1]*b
	if(w==1):
		total=gifts[0]*(a)+gifts[1]*(a+c)
	if(r==1):
		total=gifts[0]*(b+c)+gifts[1]*b
	print(total)


t=int(eval(input()))
while t>0:
	b,w=list(map(int,input().split()))
	x,y,z=list(map(int,input().split()))
	mcost=x*b+w*y
	if abs(x-y)>z:
		if x>y:
			mcost=y*(b+w)+z*b
		if y>x:
			mcost=x*(b+w)+z*w
	print(mcost)
	t=t-1



tests = int(input())

def solve(b,w,x,y,z):
	p = min(x + z,y)
	q = min(y + z,x)
	print((b * q + w * p))

for t in range(tests):
	b,w = list(map(int,input().split()))
	x,y,z = list(map(int,input().split()))
	solve(b,w,x,y,z)


t = eval(input())
while t>0:
	t-=1
	b,w = list(map(int, input().split()))
	x, y, z = list(map(int, input().split()))
	c1 = b*x + w*y
	c2 = 10000000000000000000000
	c3 = 10000000000000000000000
	c4 = b*(y+z) + w*(x+z)
	if x > y+z:
		c2 = b*(y+z) + w*y
	if y > x+z:
		c3 = w*(x+z) + b*x
#	print c1, c2, c3, c4
	print(min(c1, c2, c3, c4))


t=eval(input())
for _ in range(t):
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
	
	if b[0]>b[1]+b[2]:
		x=b[1]+b[2]
	else :
		x=b[0]
	
	if b[1]>b[0]+b[2]:
		y=b[0]+b[2]
	else :
		y=b[1]
	
	print((a[0]*x+a[1]*y))


t = int(input())
while(t>0):
	b,w = [int(i) for i in input().split()]
	x,y,z = [int(i) for i in input().split()]
	if((x<=y and y<=(x+z)) or (y<=x and x<=(y+z))):
		print(x*b + y*w)
	elif(x<y and (x+z)<y):
		print(x*b + (x+z)*w)
	elif(y<x and (y+z)<x):
		print((y+z)*b + y*w)
	t = t-1
	##22


t = eval(input())
while t>0:
	t-=1
	b,w = list(map(int, input().split()))
	x, y, z = list(map(int, input().split()))
	c1 = b*x + w*y
	c2 = 10000000000000000000000
	c3 = 10000000000000000000000
	c4 = b*(y+z) + w*(x+z)
	if x > y+z:
		c2 = b*(y+z) + w*y
	if y > x+z:
		c3 = w*(x+z) + b*x
#	print c1, c2, c3, c4
	print(min(c1, c2, c3, c4))


for _ in range(int(input())):
	b,w=(int(i) for i in input().split())
	x,y,z=(int(i) for i in input().split())
	if x==y:
		res=(b+w)*x
	elif x>z+y:
		res=b*(y+z)+w*y
	elif y>z+x:
		res=b*x+w*(z+x)
	else:
		res=b*x+y*w
	print(res)