Taum is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buy $b$ black gifts and $w$ white gifts. 

The cost  of each black gift is $bc$ units.  
The cost of every white gift is $wc$ units.  
The cost to convert a black gift into white gift or vice versa is $z$ units.  

Determine the minimum cost of Diksha's gifts.  

Example 

$b=3$ 

$w=5$ 

$bc=3$ 

$wc=4$ 

$z=1$  

He can buy a black gift for $3$ and convert it to a white gift for $1$, making the total cost of each white gift $4$.  That matches the cost of a white gift, so he can do that or just buy black gifts and white gifts.  Either way, the overall cost is $3*3+5*4=29$.  

Function Description  

Complete the function taumBday in the editor below.  It should return the minimal cost of obtaining the desired gifts.  

taumBday has the following parameter(s):  

int b: the number of black gifts  
int w: the number of white gifts  
int bc: the cost of a black gift  
int wc: the cost of a white gift  
int z: the cost to convert one color gift to the other color  

Returns  

int: the minimum cost to purchase the gifts  

Input Format

The first line will contain an integer $t$, the number of test cases. 

The next $t$ pairs of lines are as follows: 

- The first line contains the values of integers $b$ and $w$. 

- The next line contains the values of integers $bc$, $wc$, and $z$.  

Constraints

$1\leq t\leq10$ 

$0\leq b,w,bc,wc,z\leq10^9$

Output Format

$t$ lines, each containing an integer: the minimum amount of units Taum needs to spend on gifts.

Sample Input
STDIN   Function
-----   --------
5       t = 5
10 10   b = 10, w = 10
1 1 1   bc = 1, wc = 1, z = 1
5 9     b = 5, w = 5
2 3 4   bc = 2, wc = 3, z = 4
3 6     b = 3, w = 6
9 1 1   bc = 9, wc = 1, z = 1
7 7     b = 7, w = 7
4 2 1   bc = 4, wc = 2, z = 1
3 3     b = 3, w = 3
1 9 2   bc = 1, wc = 9, z = 2

Sample Output
20
37
12
35
12

Explanation

Test Case #01: 

Since black gifts cost the same as white, there is no benefit to converting the gifts.  Taum will have to buy each gift for 1 unit.  The cost of buying all gifts will be: $b*bc+w*wc=10*1+10*1=20$.  

Test Case #02: 

Again, he cannot decrease the cost of black or white gifts by converting colors. $z$ is too high.  He will buy gifts at their original prices, so the cost of buying all gifts will be: $b*bc+w*wc=5*2+9*3=10+27=37$. 

Test Case #03: 

Since $bc > wc +z$, he will buy $b+w=3+6=9$ white gifts at their original price of $1$. $b=3$ of the gifts must be black, and the cost per conversion, $z=1$.  Total cost is $9*1+3*1=12$.

Test Case #04: 

Similarly, he will buy $w=7$ white gifts at their original price, $wc=2$. For black gifts, he will first buy white ones and color them to black, so that their cost will be reduced to $wc+z=2+1=3$. So cost of buying all gifts will be: $7*3+7*2=35$.

Test Case #05: 
He will buy black gifts at their original price, $bc=1$. For white gifts, he will first black gifts worth $bc=1$ unit and color them to white for $z=2$ units.  The cost for white gifts is reduced to $wc=b c+z=2+1=3$ units. The cost of buying all gifts will be: $3*1+3*3=3+9=12$.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(b * min(x, y + z) + w * min(y, x + z))


T = int(input())
for t in range(T):
	[B, W] = map(int, input().split())
	[X, Y, Z] = map(int, input().split())
	X = min(X, Y + Z)
	Y = min(Y, X + Z)
	print(B * X + W * Y)


for _ in range(int(input())):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	v1 = x * b + y * w
	v2 = x * b + (x + z) * w
	v3 = (y + z) * b + y * w
	print(min(v1, v2, v3))


for t in range(int(input())):
	BW = [int(a) for a in input().split()]
	XYZ = [int(a) for a in input().split()]
	X = min(XYZ[0], XYZ[1] + XYZ[2])
	Y = min(XYZ[1], XYZ[0] + XYZ[2])
	print(BW[0] * X + BW[1] * Y)


for t in range(int(input())):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(b * min(x, y + z) + w * min(x + z, y))


def solve(B, W, X, Y, Z):
	return min(B * X + W * Y, B * X + W * (X + Z), B * (Y + Z) + W * Y)
T = int(input())
for _ in range(T):
	(B, W) = (int(_) for _ in input().split())
	(X, Y, Z) = (int(_) for _ in input().split())
	print(solve(B, W, X, Y, Z))


for t 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 + z:
		x = y + z
	if y > x + z:
		y = x + z
	print(x * b + y * w)


t = int(input())
for _ in range(t):
	(b, w) = [int(i) for i in input().split()]
	(x, y, z) = [int(i) for i in input().split()]
	regular = b * x + w * y
	all_black = (b + w) * x + w * z
	all_white = (b + w) * y + b * z
	print(min(regular, all_black, all_white))


tcs = int(input())
for i in range(tcs):
	(b, w) = map(int, input().split(' '))
	(x, y, z) = map(int, input().split(' '))
	if x + z < y:
		print(b * x + w * (x + z))
	elif y + z < x:
		print(w * y + b * (y + z))
	else:
		print(b * x + w * y)


times = int(input())
for _ in range(times):
	(B, W) = [int(x) for x in input().split()]
	(X, Y, Z) = [int(x) for x in input().split()]
	if X + Z < Y:
		cost = B * X + W * (X + Z)
		print(cost)
	elif Y + Z < X:
		cost = W * Y + B * (Y + Z)
		print(cost)
	else:
		cost = B * X + W * Y
		print(cost)


def cost(B, W, X, Y, Z):
	return B * min(X, Y + Z) + W * min(Y, X + Z)
num_tests = int(input())
for i in range(num_tests):
	(B, W) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	print(cost(B, W, X, Y, Z))


def main():
	t = int(input())
	for _ in range(t):
		(b, w) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		if x > y + z:
			bb = y + z
		else:
			bb = x
		if y > x + z:
			bw = x + z
		else:
			bw = y
		amount = bb * b + bw * w
		print(amount)
main()


def bcost(x, y, z):
	return min(y + z, x)

def wcost(x, y, z):
	return min(x + z, y)
t = int(input())
for _ in range(t):
	(want_b, want_w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(want_b * bcost(x, y, z) + want_w * wcost(x, y, z))


t = int(input())
for i in range(t):
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	minX = min(B[0], B[1] + B[2])
	minY = min(B[1], B[0] + B[2])
	print(A[0] * minX + A[1] * minY)


t = int(input())
for i in range(t):
	(b, w) = [int(x) for x in input().split()]
	(x, y, z) = [int(x) for x in input().split()]
	if x + z < y:
		print(b * x + w * (x + z))
	elif y + z < x:
		print(w * y + b * (y + z))
	else:
		print(b * x + w * y)


testcases = int(input())
for j in range(testcases):
	(b, w) = [int(i) for i in input().split()]
	(x, y, z) = [int(i) for i in input().split()]
	total = 0
	if x > y:
		if x > z + y:
			total += (z + y) * b
			total += y * w
		else:
			total += x * b
			total += y * w
	elif y > z + x:
		total += (z + x) * w
		total += x * b
	else:
		total += x * b
		total += y * w
	print(total)


for t in range(int(input())):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	cost = min(z + y, x) * b + min(z + x, y) * w
	print(cost)


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


t = int(input())
for i in range(t):
	(b, w) = input().split(' ')
	(x, y, z) = input().split(' ')
	(b, w) = (int(b), int(w))
	(x, y, z) = (int(x), int(y), int(z))
	s = 0
	if x + z <= y:
		s += (x + z) * w
	else:
		s += y * w
	if y + z <= x:
		s += (y + z) * b
	else:
		s += x * b
	print(s)


def best_of(B, W, X, Y, Z):
	x = min(X, Y + Z)
	y = min(Y, X + Z)
	return B * x + W * y
T = int(input())
for caca in range(T):
	(B, W) = [int(i) for i in input().split()]
	(X, Y, Z) = [int(i) for i in input().split()]
	print(best_of(B, W, X, Y, Z))


cases = int(input())
for _ in range(cases):
	(blackG, whiteG) = map(int, input().split())
	(blackCost, whiteCost, changeCost) = map(int, input().split())
	(blackCost, whiteCost) = (min(blackCost, whiteCost + changeCost), min(whiteCost, blackCost + changeCost))
	print(blackG * blackCost + whiteG * whiteCost)


T = int(input())
for i in range(T):
	(B, W) = tuple((int(x) for x in input().split()))
	(X, Y, Z) = tuple((int(x) for x in input().split()))
	if X + Z < Y:
		print(B * X + W * (X + Z))
	elif Y + Z < X:
		print(W * Y + B * (Y + Z))
	else:
		print(B * X + W * Y)


def solve(B, W, X, Y, Z):
	return min(B * X, B * (Y + Z)) + min(W * Y, W * (X + Z))
for _ in range(int(input())):
	(B, W) = [int(x) for x in input().split(' ')]
	(X, Y, Z) = [int(x) for x in input().split(' ')]
	print(solve(B, W, X, Y, Z))


T = int(input(''))
for t in range(0, T):
	line1 = input('')
	line1 = list(map(int, line1.split()))
	line2 = input('')
	line2 = list(map(int, line2.split()))
	B = line1[0]
	W = line1[1]
	X = line2[0]
	Y = line2[1]
	Z = line2[2]
	if X < Y:
		if X + Z < Y:
			print((B + W) * X + W * Z)
		else:
			print(B * X + W * Y)
	elif Y < X:
		if Y + Z < X:
			print((B + W) * Y + B * Z)
		else:
			print(B * X + W * Y)
	else:
		print(B * X + W * Y)


cases = int(input())
for _ in range(cases):
	(b, w) = [int(n) for n in input().split()]
	(x, y, z) = [int(n) for n in input().split()]
	total = 0
	if x + z < y:
		total += b * x
		total += w * (x + z)
	elif y + z < x:
		total += w * y
		total += b * (y + z)
	else:
		total += b * x
		total += w * y
	print(total)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(B, W) = list(map(int, sys.stdin.readline().split()))
	(X, Y, Z) = list(map(int, sys.stdin.readline().split()))
	if X + Z < Y:
		print(B * X + W * (X + Z))
	elif Y + Z < X:
		print(B * (Y + Z) + W * Y)
	else:
		print(B * X + W * Y)


for i in range(int(input())):
	(b, w) = [int(s) for s in input().split()]
	(x, y, z) = [int(s) for s in input().split()]
	totalGifts = b + w
	if x + z < y:
		print(totalGifts * x + w * z)
	elif y + z < x:
		print(totalGifts * y + b * z)
	else:
		print(b * x + y * w)


T = int(input())
for t in range(T):
	(B, W) = (int(x) for x in input().split())
	(X, Y, Z) = (int(x) for x in input().split())
	ans = min(X, Y + Z) * B + min(Y, X + Z) * W
	print(ans)


def main():
	for _ in range(int(input())):
		(b, w) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		if x == y:
			print(x * (b + w))
		elif x < y:
			if x + z < y:
				print(b * x + w * (x + z))
			else:
				print(b * x + w * y)
		elif y + z < x:
			print(b * (y + z) + w * y)
		else:
			print(b * x + w * y)
main()


def readInput():
	return [int(i) for i in input().split(' ')]
t = int(input())
for i in range(t):
	(b, w) = readInput()
	(x, y, z) = readInput()
	sum = 0
	blackPrice = min(x, y + z)
	whitePrice = min(y, x + z)
	sum += b * blackPrice
	sum += w * whitePrice
	print(sum)


n = int(input())
while n:
	n = n - 1
	a = input()
	(b, w) = [int(i) for i in a.split()]
	c = input()
	(x, y, z) = [int(i) for i in c.split()]
	if x < y:
		if x + z < y:
			print(b * x + (x + z) * w)
		else:
			print(b * x + w * y)
	elif y + z < x:
		print(w * y + (y + z) * b)
	else:
		print(b * x + w * y)


def main():
	ncases = int(input())
	for case in range(ncases):
		(b, w) = [int(fld) for fld in input().split(' ')]
		(x, y, z) = [int(fld) for fld in input().split(' ')]
		print(min(x, y + z) * b + min(y, x + z) * w)
	return
main()


def solvetestcase():
	(b, w) = [int(j) for j in input().split()]
	(x, y, z) = [int(k) for k in input().split()]
	ans = 0
	if x + z < y:
		ans = w * (x + z) + b * x
	elif y + z < x:
		ans = b * (y + z) + w * y
	else:
		ans = x * b + y * w
	print(ans)
testcount = int(input())
for i in range(testcount):
	solvetestcase()


def menor(a, b):
	if a < b:
		return a
	return b
T = int(input())
best = 0
while T > 0:
	(Bi, Wi) = input().split()
	(Xi, Yi, Zi) = input().split()
	b = int(Bi)
	w = int(Wi)
	x = int(Xi)
	y = int(Yi)
	z = int(Zi)
	best = b * x + w * y
	if x > y:
		best = menor(best, (b + w) * y + b * z)
	else:
		best = menor(best, (b + w) * x + w * z)
	T -= 1
	print(best)


def compute_cost(test_case):
	cost = 0
	if test_case['X'] <= test_case['YZ']:
		cost += test_case['B'] * test_case['X']
	else:
		cost += test_case['B'] * test_case['YZ']
	if test_case['Y'] <= test_case['XZ']:
		cost += test_case['W'] * test_case['Y']
	else:
		cost += test_case['W'] * test_case['XZ']
	return cost
total_cases = int(input())
test_cases = []
for test_numb in range(total_cases):
	test_case = {}
	(test_case['B'], test_case['W']) = [int(numb) for numb in input().split()]
	(test_case['X'], test_case['Y'], test_case['Z']) = [int(numb) for numb in input().split()]
	test_case['YZ'] = test_case['Y'] + test_case['Z']
	test_case['XZ'] = test_case['X'] + test_case['Z']
	test_cases.append(test_case)
for test_case in test_cases:
	cost = compute_cost(test_case)
	print(cost)


t = int(input())
for tests in range(t):
	(b, w) = [int(i) for i in input().split()]
	(x, y, z) = [int(i) for i in input().split()]
	black = min(b * (y + z), b * x)
	white = min(w * (x + z), w * y)
	print(black + white)


T = int(input())
for t in range(T):
	(B, W) = (int(x) for x in input().split())
	(X, Y, Z) = (int(x) for x in input().split())
	ans = B * min(X, Y + Z) + W * min(Y, X + Z)
	print(ans)


T = int(input())
for t in range(T):
	(b, w) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	(Aw, Ab) = (0, 0)
	if x - y >= z:
		Ab = 0
	else:
		Ab = b
	if y - x >= z:
		Aw = 0
	else:
		Aw = w
	print(Ab * (x - y - z) + Aw * (y - x - z) + (w * x + b * y + z * (b + w)))


T = int(input())
for i in range(T):
	(B, W) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	s1 = B * X + W * Y
	s2 = B * (Y + Z) + W * Y
	s3 = B * X + W * (X + Z)
	s = min(s1, s2, s3)
	print(str(s))


t = int(input())
for i in range(t):
	w_b = list(map(int, input().split()))
	x_y_z = list(map(int, input().split()))
	x_best_cost = min(x_y_z[0], x_y_z[1] + x_y_z[2])
	y_best_cost = min(x_y_z[1], x_y_z[0] + x_y_z[2])
	print(w_b[0] * x_best_cost + w_b[1] * y_best_cost)


import collections
import operator
import sys
Gift = collections.namedtuple('Gift', 'quantity, price')

def best_buy(gift1, gift2, rate):
	(cheap, expensive) = sorted([black, white], key=operator.attrgetter('price'))
	if rate + cheap.price >= expensive.price:
		return operator.mul(*gift1) + operator.mul(*gift2)
	else:
		total = expensive.quantity * (cheap.price + rate)
		total += cheap.price * cheap.quantity
		return total
ncases = int(sys.stdin.readline())
for _ in range(ncases):
	(b, w) = (int(x) for x in sys.stdin.readline().split())
	(x, y, rate) = (int(x) for x in sys.stdin.readline().split())
	black = Gift(b, x)
	white = Gift(w, y)
	print(best_buy(black, white, rate))


test_count = int(input())
for i in range(0, test_count):
	count = list(map(int, input().split()))
	black_count = count[0]
	white_count = count[1]
	price = list(map(int, input().split()))
	black_price = price[0]
	white_price = price[1]
	conversion_price = price[2]
	total = 0
	if black_price < white_price:
		total = black_price * black_count
		if black_price + conversion_price < white_price:
			total += (black_price + conversion_price) * white_count
		else:
			total += white_price * white_count
	else:
		total = white_price * white_count
		if white_price + conversion_price < black_price:
			total += (white_price + conversion_price) * black_count
		else:
			total += black_price * black_count
	print(total)


t = int(input())
while t > 0:
	t -= 1
	mylist = []
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	mylist.append(b * x + w * y)
	mylist.append(b * z + (b + w) * y)
	mylist.append(w * z + (b + w) * x)
	print(min(mylist))


T = int(input())
for i in range(T):
	numbers = list(map(int, input().split()))
	B = numbers[0]
	W = numbers[1]
	numbers = list(map(int, input().split()))
	X = numbers[0]
	Y = numbers[1]
	Z = numbers[2]
	if X - Y > Z:
		ans = (B + W) * Y + B * Z
	elif Y - X > Z:
		ans = (B + W) * X + W * Z
	else:
		ans = B * X + W * Y
	print(ans)


for t in range(int(input())):
	(qb, qw) = [int(i) for i in input().split(' ')]
	(pb, pw, z) = [int(i) for i in input().split(' ')]
	if pb + z < pw:
		pw = pb + z
	elif pw + z < pb:
		pb = pw + z
	total = pb * qb + pw * qw
	print(str(total))


t = int(input())
for case in range(t):
	BW = input().split(' ')
	(b, w) = tuple([int(i) for i in BW])
	XYZ = input().split(' ')
	(x, y, z) = tuple([int(i) for i in XYZ])
	if x + z < y:
		print(b * x + w * (x + z))
	elif y + z < x:
		print(b * (y + z) + w * y)
	else:
		print(b * x + w * y)


t = int(input())
for a in range(0, t):
	numbers = list(map(int, input().split()))
	b = numbers[0]
	w = numbers[1]
	numbers = list(map(int, input().split()))
	x = numbers[0]
	y = numbers[1]
	z = numbers[2]
	total = 0
	if x > y and z + y < x:
		total += w * y
		total += b * y
		total += b * z
	elif y > x and z + x < y:
		total += b * x
		total += w * x
		total += w * z
	else:
		total += b * x
		total += w * y
	print(str(total))


__author__ = 'nolanemirot'

def howMuckspendOnGift(B, W, X, Y, Z):
	casa = B * X + W * Y
	casb = X * (B + W) + Z * W
	casc = Y * (B + W) + Z * B
	return min([casa, casb, casc])
nbTestCase = int(input())
i = 0
while i < nbTestCase:
	line = input()
	arrl = list(map(int, line.split()))
	B = arrl[0]
	W = arrl[1]
	line2 = input()
	arrl2 = list(map(int, line2.split()))
	X = arrl2[0]
	Y = arrl2[1]
	Z = arrl2[2]
	print(howMuckspendOnGift(B, W, X, Y, Z))
	i += 1


T = int(input())
for i in range(T):
	costs = [int(num) for num in input().split()]
	count = [int(num) for num in input().split()]
	tempcost = [0, 0, 0]
	tempcost[0] = count[0] * costs[0] + count[1] * costs[1]
	tempcost[1] = (costs[0] + costs[1]) * count[0] + count[2] * costs[1]
	tempcost[2] = (costs[0] + costs[1]) * count[1] + count[2] * costs[0]
	print(min(tempcost))


t = int(input())
while t > 0:
	t -= 1
	g = list(map(int, input().split()))
	p = list(map(int, input().split()))
	x = [min(p[0:2]), max(p[0:2])]
	d = x[1] - x[0]
	if p[0] == x[0]:
		if d > p[2]:
			print(sum(g) * x[0] + p[2] * g[1])
		else:
			print(g[1] * p[1] + g[0] * p[0])
	elif d > p[2]:
		print(sum(g) * x[0] + p[2] * g[0])
	else:
		print(g[1] * p[1] + g[0] * p[0])


T = input()
for i in range(int(T)):
	(B, W) = list(map(int, input().split(' ')))
	(X, Y, Z) = list(map(int, input().split(' ')))
	s = B + W
	if X + Z < Y:
		output = s * X + W * Z
	elif Y + Z < X:
		output = s * Y + B * Z
	else:
		output = B * X + W * Y
	print(output)


T = int(input())
for i in range(T):
	first = input().split(' ')
	bNum = int(first[0])
	wNum = int(first[1])
	second = input().split(' ')
	bCost = int(second[0])
	wCost = int(second[1])
	convCost = int(second[2])
	minCost = 0
	if bCost + convCost < wCost:
		minCost = bCost * bNum + (bCost + convCost) * wNum
	elif wCost + convCost < bCost:
		minCost = (wCost + convCost) * bNum + wCost * wNum
	else:
		minCost = bCost * bNum + wCost * wNum
	print(str(minCost))


for _ in range(int(input())):
	(B, W) = [int(x) for x in input().split(' ')]
	(X, Y, Z) = [int(x) for x in input().split(' ')]
	print(min(B * X + W * Y, min(B * X + W * X + W * Z, W * Y + B * Y + B * Z)))


t = int(input())
for _ in range(t):
	(black_count, white_count) = map(int, input().split())
	(black_cost, white_cost, convert_cost) = map(int, input().split())
	cost = (black_count + white_count) * black_cost + convert_cost * white_count
	cost = min(cost, (black_count + white_count) * white_cost + convert_cost * black_count)
	cost = min(cost, black_count * black_cost + white_count * white_cost)
	print(cost)


import math
num_cases = int(input())
for case_num in range(0, num_cases):
	BW = input().split(' ')
	B = int(BW[0])
	W = int(BW[1])
	XYZ = input().split(' ')
	X = int(XYZ[0])
	Y = int(XYZ[1])
	Z = int(XYZ[2])
	g_min = min(X, Y)
	g_max = max(X, Y)
	if g_min + Z < g_max:
		if g_min == X:
			print(B * X + W * (X + Z))
		else:
			print(W * Y + B * (Y + Z))
	else:
		print(B * X + W * Y)


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


from sys import stdin
tests = int(stdin.readline().strip())
for x in range(tests):
	(black, white) = [int(v) for v in stdin.readline().strip().split(' ')]
	(bcost, wcost, delta) = [int(v) for v in stdin.readline().strip().split(' ')]
	if bcost < wcost:
		scost = bcost + delta
		if scost < wcost:
			print(scost * white + bcost * black)
		else:
			print(wcost * white + bcost * black)
	elif wcost < bcost:
		scost = wcost + delta
		if scost < bcost:
			print(scost * black + wcost * white)
		else:
			print(wcost * white + bcost * black)
	else:
		print(bcost * (black + white))


def run():
	min_cost = []
	T = int(input())
	for i in range(T):
		BW = input().split()
		XYZ = input().split()
		num_black = int(BW[0])
		num_white = int(BW[1])
		cost_black = int(XYZ[0])
		cost_white = int(XYZ[1])
		conversion = int(XYZ[2])
		if num_black * cost_black > num_black * conversion + num_black * cost_white:
			num_white += num_black
			total_cost = num_white * cost_white + num_black * conversion
		elif num_white * cost_white > num_white * conversion + num_white * cost_black:
			num_black += num_white
			total_cost = num_black * cost_black + num_white * conversion
		else:
			total_cost = num_black * cost_black + num_white * cost_white
		min_cost.append(total_cost)
	for i in min_cost:
		print(i)
run()


test_cases = int(input())
gift_list = []
cost_list = []
print_cost = []
for i in range(test_cases):
	gift_list.append(input())
	cost_list.append(input())
for i in range(test_cases):
	black_and_white = gift_list[i].split(' ')
	num_black = int(black_and_white[0])
	num_white = int(black_and_white[1])
	individual_cost = cost_list[i].split(' ')
	black_cost = int(individual_cost[0])
	white_cost = int(individual_cost[1])
	switch_cost = int(individual_cost[2])
	switch_to_black_cost = white_cost + switch_cost
	switch_to_white_cost = black_cost + switch_cost
	if switch_to_black_cost < black_cost:
		black_cost = switch_to_black_cost
	if switch_to_white_cost < white_cost:
		white_cost = switch_to_white_cost
	total_cost = num_black * black_cost + num_white * white_cost
	print_cost.append(total_cost)
for i in range(test_cases):
	print(print_cost[i])


t = int(input())
while t > 0:
	s1 = str(input())
	s2 = str(input())
	lt1 = s1.split()
	lt1 = list(map(int, lt1))
	lt2 = s2.split()
	lt2 = list(map(int, lt2))
	an = 0
	ans = 0
	out = 0
	an = lt2[2] * lt1[1] + (lt1[1] + lt1[0]) * lt2[0]
	ans = lt2[2] * lt1[0] + (lt1[1] + lt1[0]) * lt2[1]
	out = int(lt1[0] * lt2[0] + lt1[1] * lt2[1])
	print(min(int(an), int(ans), out))
	t = t - 1


T = int(input())
for i in range(T):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = x * b + y * w
	ans = min(ans, (b + w) * x + z * w)
	ans = min(ans, (b + w) * y + z * b)
	print(ans)


testCase = int(input())
while testCase > 0:
	BW = input().split(' ')
	costs = input().split(' ')
	BW = [int(i) for i in BW]
	costs = [int(i) for i in costs]
	ans1 = BW[0] * costs[0] + BW[1] * costs[1]
	ans2 = (BW[0] + BW[1]) * costs[0] + BW[1] * costs[2]
	ans3 = (BW[0] + BW[1]) * costs[1] + BW[0] * costs[2]
	print(min(ans1, min(ans2, ans3)))
	testCase -= 1


numTestCases = int(input())
for i in range(numTestCases):
	line1 = list(map(int, input().split(' ')))
	line2 = list(map(int, input().split(' ')))
	B = line1[0]
	W = line1[1]
	X = line2[0]
	Y = line2[1]
	Z = line2[2]
	if X > Y:
		if Y + Z < X:
			print(B * (Y + Z) + W * Y)
		else:
			print(B * X + W * Y)
	elif X < Y:
		if X + Z < Y:
			print(B * X + W * (X + Z))
		else:
			print(B * X + W * Y)
	else:
		print(B * X + W * Y)


def min_cost(b, w, x, y, z):
	return min((b * x + w * y, (b + w) * x + w * z, b * z + (b + w) * y))
t = int(input())
for _ in range(t):
	(b, w) = [int(el) for el in input().split()]
	(x, y, z) = [int(el) for el in input().split()]
	print(min_cost(b, w, x, y, z))


t = int(input())
for _ in range(t):
	(B, W) = (int(x) for x in input().split())
	(X, Y, Z) = (int(x) for x in input().split())
	amount = B * X + W * Y
	B_converted = B * Z + (B + W) * Y
	if amount > B_converted:
		amount = B_converted
	W_converted = W * Z + (B + W) * X
	if amount > W_converted:
		amount = W_converted
	print(amount)


def gifts(b, w, x, y, z):
	b_cost = x if y + z > x else y + z
	w_cost = y if x + z > y else x + z
	return b * b_cost + w * w_cost
t = int(input())
for _ in range(t):
	(b, w) = [int(x) for x in input().split()]
	(x, y, z) = [int(x) for x in input().split()]
	print(gifts(b, w, x, y, z))


test_cases = int(input())
for i in range(test_cases):
	bw = list(map(int, input().split()))
	xyz = list(map(int, input().split()))
	b = bw[0]
	w = bw[1]
	x = xyz[0]
	y = xyz[1]
	z = xyz[2]
	result = 0
	if x <= y:
		result += b * x
		if x + z <= y:
			result += w * (x + z)
		else:
			result += w * y
	else:
		result += w * y
		if y + z <= x:
			result += b * (y + z)
		else:
			result += b * x
	print(result)


for t in range(int(input())):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	if x > y:
		(x, y, b, w) = (y, x, w, b)
	print(x * b + (x + z) * w if y > x + z else x * b + y * w)


for T in range(int(input())):
	(B, W) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	(P1, P2, P3) = (X * B + Y * W, Y * W + B * (Y + Z), X * B + W * (X + Z))
	print(min(P1, P2, P3))


t = int(input())
while t > 0:
	(b, w) = input().split()
	b = int(b)
	w = int(w)
	(x, y, z) = input().split()
	x = int(x)
	y = int(y)
	z = int(z)
	total = 0
	if x > y + z:
		total = b * (y + z) + w * y
	elif y > x + z:
		total = b * x + w * (x + z)
	else:
		total = b * x + w * y
	print(total)
	t -= 1


for _ in range(0, int(input())):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(min(b * x + y * w, min(b * x + w * (x + z), b * (y + z) + w * y)))


def fun(b, w, x, y, z):
	res = 0
	if x == y:
		return (b + w) * x
	if x < y:
		res += b * x
		if y < x + z:
			res += w * y
		else:
			res += w * (x + z)
		return res
	if y < x:
		res += w * y
		if x < y + z:
			res += b * x
		else:
			res += b * (y + z)
		return res
t = int(input())
for _ in range(t):
	(b, w) = [int(c) for c in input().split()]
	(x, y, z) = [int(c) for c in input().split()]
	print(fun(b, w, x, y, z))


t = int(input())
for _ in range(0, t):
	(b, w) = [int(x) for x in input().split(' ')]
	(x, y, z) = [int(x) for x in input().split(' ')]
	x = x if y + z > x else y + z
	y = y if x + z > y else x + z
	print(str(b * x + w * y))


import math
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 min(x, y) + z < max(x, y):
		if x < y:
			y = x + z
		else:
			x = y + z
	print(b * x + w * y)


def howMuckspendOnGift(B, W, X, Y, Z):
	casa = B * X + W * Y
	casb = X * (B + W) + Z * W
	casc = Y * (B + W) + Z * B
	return min([casa, casb, casc])
nbTestCase = int(input())
i = 0
while i < nbTestCase:
	line = input()
	arrl = list(map(int, line.split()))
	B = arrl[0]
	W = arrl[1]
	line2 = input()
	arrl2 = list(map(int, line2.split()))
	X = arrl2[0]
	Y = arrl2[1]
	Z = arrl2[2]
	print(howMuckspendOnGift(B, W, X, Y, Z))
	i += 1


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


testCaseCount = int(input())
testCases = []
for i in range(testCaseCount):
	testCase = {}
	(testCase['B'], testCase['W']) = [int(i) for i in input().split(' ')]
	(testCase['X'], testCase['Y'], testCase['Z']) = [int(i) for i in input().split(' ')]
	testCases.append(testCase)
solutions = []
for tc in testCases:
	totalCost = tc['X'] * tc['B'] + tc['Y'] * tc['W']
	if tc['X'] + tc['Z'] < tc['Y']:
		totalCost = totalCost - tc['Y'] * tc['W'] + tc['Z'] * tc['W'] + tc['X'] * tc['W']
	elif tc['Y'] + tc['Z'] < tc['X']:
		totalCost = totalCost - tc['X'] * tc['B'] + tc['Z'] * tc['B'] + tc['Y'] * tc['B']
	solutions.append(totalCost)
[print(str(solution)) for solution in solutions]


t = int(input())
for _ in range(t):
	(b, w) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(b * min(x, y + z) + w * min(y, x + z))


T = int(input())
for _ in range(T):
	(B, W) = [int(c) for c in input().strip().split()]
	(X, Y, Z) = [int(c) for c in input().strip().split()]
	cost_B = min(X, Y + Z)
	cost_W = min(Y, X + Z)
	print(cost_B * B + cost_W * W)


class BdayGifts:

	def __init__(self, bw_gifts, cost_amts):
		(self.black_gifts, self.white_gifts) = [int(num) for num in bw_gifts.split(' ')]
		cost_amts = [int(amt) for amt in cost_amts.split(' ')]
		self.black_cost = cost_amts[0]
		self.white_cost = cost_amts[1]
		self.trade_cost = cost_amts[2]
		self.spent = 0
		self.black_bought = 0
		self.white_bought = 0

	def buy_black(self, amount):
		self.spent += amount * self.black_cost
		self.black_bought += amount

	def buy_white(self, amount):
		self.spent += amount * self.white_cost
		self.white_bought += amount

	def trade_black(self, trades):
		self.spent += trades * self.trade_cost
		self.black_bought -= trades
		self.white_bought += trades

	def trade_white(self, trades):
		self.spent += trades * self.trade_cost
		self.white_bought -= trades
		self.black_bought += trades

	def purchases(self):
		if self.black_cost + self.trade_cost < self.white_cost:
			self.buy_black(self.white_gifts)
			self.trade_black(self.white_gifts)
		if self.white_cost + self.trade_cost < self.black_cost:
			self.buy_white(self.black_gifts)
			self.trade_white(self.black_gifts)
		black_diff = self.black_gifts - self.black_bought
		if black_diff > 0:
			self.buy_black(black_diff)
		white_diff = self.white_gifts - self.white_bought
		if white_diff > 0:
			self.buy_white(white_diff)
		return self.spent
cases = input()
for case in range(0, int(cases)):
	gifts = input()
	cost = input()
	bday_gifts = BdayGifts(gifts, cost)
	min_spend = bday_gifts.purchases()
	print(min_spend)


def giftcost(x, y):
	NoSubsCost = x[0] * y[0] + x[1] * y[1]
	if y[2] == y[0] and y[2] == y[1]:
		return NoSubsCost
	elif y[1] < y[0]:
		SubCost = (x[0] + x[1]) * y[1] + x[0] * y[2]
		if SubCost < NoSubsCost:
			return SubCost
		else:
			return NoSubsCost
	elif y[0] < y[1]:
		SubCost = (x[0] + x[1]) * y[0] + x[1] * y[2]
		if SubCost < NoSubsCost:
			return SubCost
		else:
			return NoSubsCost
	else:
		return NoSubsCost
a = int(input())
for i in range(a):
	b = input()
	b = b.strip().split(' ')
	b = [int(x) for x in b]
	c = input()
	c = c.strip().split(' ')
	c = [int(x) for x in c]
	print(giftcost(b, c))


for T in range(int(input())):
	(b, w) = (int(i) for i in input().split())
	(x, y, z) = (int(i) for i in input().split())
	m1 = b * x + w * y
	m2 = b * x + w * (x + z)
	m3 = b * (y + z) + w * y
	print(min(m1, min(m2, m3)))


T = int(input())
for t in range(0, T):
	line = [int(z) for z in input().split()]
	B = line[0]
	W = line[1]
	line = [int(z) for z in input().split()]
	X = line[0]
	Y = line[1]
	Z = line[2]
	print(min(B * X + W * Y, B * X + W * (X + Z), W * Y + B * (Y + Z)))


t = int(input())
for i in range(t):
	(B, W) = input().split()
	(B, W) = (int(B), int(W))
	(X, Y, Z) = input().split()
	(X, Y, Z) = (int(X), int(Y), int(Z))
	g = B * X + W * Y
	h = B * X + W * (X + Z)
	i = B * (Y + Z) + W * Y
	print(min(g, min(h, i)))


for i in range(int(input())):
	b_w = list(map(int, input().split()))
	xyz = list(map(int, input().split()))
	x = xyz[0]
	y = xyz[1]
	z = xyz[2]
	if z + x < y:
		y = z + x
	if z + y < x:
		x = z + y
	b = b_w[0] * x
	w = b_w[1] * y
	print(b + w)


def amount(b, w, x, y, z):
	real_price_black = min(x, y + z)
	real_price_white = min(y, x + z)
	return b * real_price_black + w * real_price_white

def main():
	t = int(input())
	for x in range(t):
		(b, w) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		print(amount(b, w, x, y, z))
main()


t = int(input())
for tests in range(t):
	(b, w) = input().split()
	(x, y, z) = input().split()
	(b, w, x, y, z) = (int(b), int(w), int(x), int(y), int(z))
	answer = 0
	if x > y + z:
		w += b
		answer += b * z
		b = 0
	elif y > x + z:
		b += w
		answer += w * z
		w = 0
	answer += b * x + w * y
	print(answer)


import sys
__author__ = 'nutic'
lines = sys.stdin.read().split('\n')
lines = iter(lines)
n = int(next(lines))

def read_line_of_numbers(line: str, number_type=int):
	return list(map(number_type, line.split(' ')))

def get_white_cost(b_cost, w_cost, change_cost):
	return min(w_cost, b_cost + change_cost)

def get_black_cost(b_cost, w_cost, change_cost):
	return min(b_cost, w_cost + change_cost)
for i in range(0, n):
	(b, w, *_) = read_line_of_numbers(next(lines))
	(x, y, z, *_) = read_line_of_numbers(next(lines))
	sys.stdout.write(str(get_white_cost(x, y, z) * w + get_black_cost(x, y, z) * b))
	sys.stdout.write('\n')


def gift_cost(b, w, x, y, z):
	if x < y:
		if x + z < y:
			y = x + z
	elif y + z < x:
		x = y + z
	return b * x + w * y
for i in range(0, int(input())):
	(b, w) = input().split()
	(b, w) = (int(b), int(w))
	(x, y, z) = input().split()
	(x, y, z) = (int(x), int(y), int(z))
	print(gift_cost(b, w, x, y, z))


import sys
line = sys.stdin.readline()
N = int(line)
for i in range(0, N):
	line = sys.stdin.readline()
	B = int(line.split()[0])
	W = int(line.split()[1])
	line = sys.stdin.readline()
	X = int(line.split()[0])
	Y = int(line.split()[1])
	Z = int(line.split()[2])
	if X == Y:
		print((B + W) * X)
	elif X > Y:
		if Y + Z < X:
			print(B * (Y + Z) + W * Y)
		else:
			print(B * X + W * Y)
	elif X + Z < Y:
		print(B * X + W * (X + Z))
	else:
		print(B * X + W * Y)


T = int(input())
for t in range(T):
	(B, W) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	the_cheapest = min(X, Y)
	if the_cheapest == X == Y:
		print(str(X * B + Y * W))
	elif the_cheapest == X and X + Z < Y:
		print(str(X * (B + W) + Z * W))
	elif the_cheapest == Y and Y + Z < X:
		print(str(Y * (B + W) + Z * B))
	else:
		print(str(X * B + Y * W))


t = int(input())
for counter in range(t):
	inStr = input().split()
	b = int(inStr[0])
	w = int(inStr[1])
	inStr = input().split()
	x = int(inStr[0])
	y = int(inStr[1])
	z = int(inStr[2])
	total = min(x, y + z) * b + min(y, x + z) * w
	print(total)


T = int(input())
for _ in range(T):
	(B, W) = input().split()
	(B, W) = (int(B), int(W))
	(b_cost, w_cost, swap_cost) = input().split()
	(b_cost, w_cost, swap_cost) = (int(b_cost), int(w_cost), int(swap_cost))
	total_cost = min(b_cost, w_cost + swap_cost) * B + min(w_cost, b_cost + swap_cost) * W
	print(total_cost)


def f(b, w, x, y, z):
	if x == y:
		return b * x + w * y
	elif x > y:
		if x <= y + z:
			return b * x + w * y
		else:
			return b * (y + z) + w * y
	elif y <= x + z:
		return b * x + w * y
	else:
		return b * x + w * (x + z)
T = int(input())
for i in range(T):
	(b, w) = [int(ns) for ns in str(input()).split()]
	(x, y, z) = [int(ns) for ns in str(input()).split()]
	print(f(b, w, x, y, z))


for a in range(int(input())):
	(b_cnt, w_cnt) = [int(b) for b in input().strip().split()]
	(b_cst, w_cst, conv_cst) = [int(b) for b in input().strip().split()]
	if b_cst + conv_cst < w_cst:
		(b_pr, w_pr) = (b_cst, b_cst + conv_cst)
	elif w_cst + conv_cst < b_cst:
		(b_pr, w_pr) = (w_cst + conv_cst, w_cst)
	else:
		(b_pr, w_pr) = (b_cst, w_cst)
	print(b_pr * b_cnt + w_pr * w_cnt)


n = int(input())
for i in range(n):
	(numblack, numwhite) = input().split()
	(numblack, numwhite) = (int(numblack), int(numwhite))
	(costofblack, costofwhite, costofconvert) = input().split()
	(costofblack, costofwhite, costofconvert) = (int(costofblack), int(costofwhite), int(costofconvert))
	if abs(costofblack - costofwhite) <= costofconvert:
		money = costofblack * numblack + costofwhite * numwhite
		print(money)
	elif costofblack >= costofwhite:
		money = costofwhite * numwhite + (costofwhite + costofconvert) * numblack
		print(money)
	else:
		money = costofblack * numblack + (costofblack + costofconvert) * numwhite
		print(money)


def minPrice(black, white, b_price, w_price, shift_price):
	if b_price == w_price:
		return black * b_price + white * w_price
	else:
		min_price = min(b_price, w_price)
		if min_price == b_price:
			sp_or_wp = min(b_price + shift_price, w_price)
			if sp_or_wp == b_price + shift_price:
				init_price = black * b_price + white * (b_price + shift_price)
			else:
				init_price = black * b_price + white * w_price
		else:
			sp_or_wp = min(w_price + shift_price, b_price)
			if sp_or_wp == w_price + shift_price:
				init_price = black * (w_price + shift_price) + white * w_price
			else:
				init_price = black * b_price + white * w_price
	return init_price
t = int(input())
for case in range(t):
	candies = input().split()
	black = int(candies[0])
	white = int(candies[1])
	prices = input().split()
	b_price = int(prices[0])
	w_price = int(prices[1])
	shift_price = int(prices[2])
	print(minPrice(black, white, b_price, w_price, shift_price))


t = int(input())
for i in range(t):
	(b, w) = [int(s) for s in str(input()).split()]
	(x, y, z) = [int(s) for s in str(input()).split()]
	(mx, my) = (min(x, y + z), min(y, x + z))
	print(b * mx + w * my)


T = input()
for t in range(int(T)):
	(b, w) = input().split()
	(b, w) = (int(b), int(w))
	costs = input().split()
	x = int(costs[0])
	y = int(costs[1])
	z = int(costs[2])
	total = x * b + y * w
	whites = b * x + w * (z + x)
	blacks = w * y + b * (z + y)
	mm = min(total, whites, blacks)
	print(mm)


T = int(input())
for i in range(T):
	(B, W) = (int(a) for a in input().split())
	(X, Y, Z) = (int(a) for a in input().split())
	if Y > X + Z:
		Y = X + Z
	elif X > Y + Z:
		X = Y + Z
	print(B * X + W * Y)