There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet. 

You have $b$ buns, $p$ beef patties and $f$ chicken cutlets in your restaurant. You can sell one hamburger for $h$ dollars and one chicken burger for $c$ dollars. Calculate the maximum profit you can achieve.

You have to answer $t$ independent queries.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 100$) – the number of queries.

The first line of each query contains three integers $b$, $p$ and $f$ ($1 \le b, ~p, ~f \le 100$) — the number of buns, beef patties and chicken cutlets in your restaurant.

The second line of each query contains two integers $h$ and $c$ ($1 \le h, ~c \le 100$) — the hamburger and chicken burger prices in your restaurant.


-----Output-----

For each query print one integer — the maximum profit you can achieve.


-----Example-----
Input
3
15 2 3
5 10
7 5 2
10 12
1 100 100
100 100

Output
40
34
0



-----Note-----

In first query you have to sell two hamburgers and three chicken burgers. Your income is $2 \cdot 5 + 3 \cdot 10 = 40$.

In second query you have to ell one hamburgers and two chicken burgers. Your income is $1 \cdot 10 + 2 \cdot 12 = 34$.

In third query you can not create any type of burgers because because you have only one bun. So your income is zero.

Difficulty: EASY
Tags: Mathematics

Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if h > c:
		ans += min(b // 2, p) * h
		b -= ans * 2 / h
		ans += min(b // 2, f) * c
	else:
		ans += min(b // 2, f) * c
		b -= ans * 2 / c
		ans += min(b // 2, p) * h
	print(int(ans))


for i in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(h, k) = list(map(int, input().split()))
	d = 0
	if a == 1:
		print(0)
	elif k > h:
		d = min(a // 2, c) * k
		e = min((a - c * 2) // 2, b) * h
		print(d + max(0, e))
	else:
		d = min(a // 2, b) * h
		e = min((a - b * 2) // 2, c) * k
		print(d + max(0, e))


n = int(input())
for i in range(n):
	count = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		while b > 1 and p != 0:
			count = count + h
			b = b - 2
			p = p - 1
		while b > 1 and f != 0:
			count = count + c
			b = b - 2
			f = f - 1
	if c > h:
		while b > 1 and f >= 1:
			count = count + c
			b = b - 2
			f = f - 1
		while b > 1 and p >= 1:
			count = count + h
			b = b - 2
			p = p - 1
	print(count)


def main():
	t = int(input())
	for _ in range(t):
		(b, p, q) = [int(s) for s in input().split()]
		(h, c) = [int(s) for s in input().split()]
		sol = 0
		if h > c:
			if p <= b // 2:
				b -= 2 * p
				sol += p * h
				sol += min(b // 2, q) * c
			else:
				sol += b // 2 * h
		elif q <= b // 2:
			b -= 2 * q
			sol += q * c
			sol += min(b // 2, p) * h
		else:
			sol += b // 2 * c
		print(sol)
main()


x = int(input())
y = []
z = []
for c in range(x):
	y.append(list(map(int, input().split())))
	z.append(list(map(int, input().split())))
for c in range(x):
	pat = y[c][0] // 2
	beef = y[c][1]
	chick = y[c][2]
	pricebeef = z[c][0]
	pricechick = z[c][1]
	win = 0
	if pricechick >= pricebeef:
		while chick > 0 and pat > 0:
			win = win + pricechick
			chick = chick - 1
			pat = pat - 1
		while beef > 0 and pat > 0:
			win = win + pricebeef
			beef = beef - 1
			pat = pat - 1
	if pricechick < pricebeef:
		while beef > 0 and pat > 0:
			win = win + pricebeef
			beef = beef - 1
			pat = pat - 1
		while chick > 0 and pat > 0:
			win = win + pricechick
			chick = chick - 1
			pat = pat - 1
	print(win)


import sys, math

def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(b, p, f) = mii()
		(h, c) = mii()
		(db, dp, df) = (b, p, f)
		x = min(p, b // 2)
		b -= 2 * x
		y = min(b // 2, f)
		dx = min(db // 2, df)
		db -= 2 * dx
		dy = min(db // 2, dp)
		print(max(h * x + c * y, h * dy + c * dx))
main()


n = int(input())
for i in range(n):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	k = b // 2
	t = 0
	if h > c:
		if k > p:
			k -= p
			t += p * h
			if k > f:
				t += f * c
			else:
				t += k * c
		else:
			t += k * h
	elif k > f:
		k -= f
		t += f * c
		if k > p:
			t += p * h
		else:
			t += k * h
	else:
		t += k * c
	print(t)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	k = b // 2
	if h > c:
		r = 0
		l = min(k, p)
		r = r + l * h
		k = k - l
		if k > 0:
			l = min(k, f)
			r = r + l * c
		print(r)
	else:
		r = 0
		l = min(k, f)
		r = r + l * c
		k = k - l
		if k > 0:
			l = min(k, p)
			r = r + l * h
		print(r)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	s = 0
	if x > y:
		if a // 2 >= b:
			s += b * x
			a -= b * 2
			if a // 2 > c:
				s += c * y
			else:
				s += y * (a // 2)
		else:
			s += x * (a // 2)
	elif a // 2 >= c:
		s += c * y
		a -= c * 2
		if a // 2 > b:
			s += b * x
		else:
			s += x * (a // 2)
	else:
		s += y * (a // 2)
	print(s)


for i in range(int(input())):
	(m, s) = (0, 0)
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		m = min(p, b // 2)
		s += h * m
		s += c * min(f, b // 2 - m)
	else:
		m = min(f, b // 2)
		s += c * m
		s += h * min(p, b // 2 - m)
	print(s)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		if b // 2 > p:
			cnt_0 = p
			b = b - p * 2
			if b // 2 > f:
				cnt_1 = f
			else:
				cnt_1 = b // 2
		else:
			cnt_0 = b // 2
			cnt_1 = 0
	elif b // 2 > f:
		cnt_1 = f
		b = b - f * 2
		if b // 2 > p:
			cnt_0 = p
		else:
			cnt_0 = b // 2
	else:
		cnt_0 = 0
		cnt_1 = b // 2
	m = cnt_0 * h + cnt_1 * c
	print(m)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	money = 0
	if h > c:
		k = min(p, b // 2)
		p -= k
		b -= 2 * k
		money += h * k
		k = min(f, b // 2)
		f -= k
		b -= 2 * k
		money += c * k
		print(money)
	else:
		k = min(f, b // 2)
		f -= k
		b -= 2 * k
		money += c * k
		k = min(p, b // 2)
		p -= k
		b -= 2 * k
		money += h * k
		print(money)


a = int(input())
for i in range(a):
	l1 = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	pro = 0
	buns = int(l1[0] / 2)
	beef = l1[1]
	chicken = l1[2]
	ham = l2[0]
	chi = l2[1]
	if ham > chi:
		if beef > buns:
			pro = pro + buns * ham
		elif beef == buns:
			pro = pro + ham * beef
		elif beef < buns and buns - beef < chicken:
			pro = pro + ham * beef
			pro = pro + (buns - beef) * chi
		elif beef < buns and buns - beef >= chicken:
			pro = pro + ham * beef
			pro = pro + chicken * chi
	elif chi > ham:
		if chicken > buns:
			pro = pro + buns * chi
		elif chicken == buns:
			pro = pro + chi * chicken
		elif chicken < buns and buns - chicken < beef:
			pro = pro + chi * chicken
			pro = pro + (buns - chicken) * ham
		elif chicken < buns and buns - chicken >= beef:
			pro = pro + chi * chicken
			pro = pro + beef * ham
	elif ham == chi:
		if beef + chicken > buns:
			pro = pro + buns * ham
		else:
			pro = pro + (beef + chicken) * ham
	print(pro)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		r = min(b // 2, p)
		ans = r * h + min((b - 2 * r) // 2, f) * c
	else:
		r = min(b // 2, f)
		ans = r * c + min((b - 2 * r) // 2, p) * h
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	need = b // 2
	inc = 0
	if h > c:
		if need > p:
			inc += h * p
			if need - p > f:
				inc += c * f
			else:
				inc += c * (need - p)
		else:
			inc += h * need
	elif need > f:
		inc += c * f
		if need - f > p:
			inc += h * p
		else:
			inc += h * (need - f)
	else:
		inc += c * need
	print(inc)


t = int(input())
for i in range(t):
	(bun, patty, cutlet) = [int(tmp) for tmp in input().split()]
	(h, c) = [int(tmp) for tmp in input().split()]
	ans = 0
	if h > c:
		ans = ans + h * min(bun // 2, patty)
		bun -= 2 * min(bun // 2, patty)
		ans = ans + c * min(bun // 2, cutlet)
		bun -= 2 * min(bun // 2, cutlet)
	else:
		ans = ans + c * min(bun // 2, cutlet)
		bun -= 2 * min(bun // 2, cutlet)
		ans = ans + h * min(bun // 2, patty)
		bun -= 2 * min(bun // 2, patty)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	line1 = input()
	(b, p, f) = (int(line1.split(' ')[0]), int(line1.split(' ')[1]), int(line1.split(' ')[2]))
	line2 = input()
	(h, c) = (int(line2.split(' ')[0]), int(line2.split(' ')[1]))
	price = 0
	if c > h:
		max_price = c
		max_raw_material = f
		min_price = h
		min_raw_material = p
	else:
		max_price = h
		max_raw_material = p
		min_price = c
		min_raw_material = f
	least = min(b // 2, max_raw_material)
	b -= 2 * least
	price = least * max_price
	least = min(b // 2, min_raw_material)
	price += least * min_price
	print(price)


t = int(input())
output = []
for _ in range(t):
	(buns, beef_patties, chicken_cutlets) = map(int, input().split())
	(ham_pri, chic_pri) = map(int, input().split())
	profit = 0
	num_bur = int(buns / 2)
	if buns == 1 or buns == 0:
		output.append(0)
	else:
		for i in range(num_bur):
			if ham_pri >= chic_pri:
				if beef_patties > 0:
					profit += ham_pri
					beef_patties -= 1
				elif chicken_cutlets > 0:
					profit += chic_pri
					chicken_cutlets -= 1
				else:
					continue
			elif ham_pri <= chic_pri:
				if chicken_cutlets > 0:
					profit += chic_pri
					chicken_cutlets -= 1
				elif beef_patties > 0:
					profit += ham_pri
					beef_patties -= 1
				else:
					continue
			else:
				continue
		output.append(profit)
for x in output:
	print(x)


T = int(input())
for _ in range(T):
	[b, p, f] = [int(x) for x in input().split()]
	[h, c] = [int(x) for x in input().split()]
	ats = 0
	if h >= c:
		ats += min(b // 2, p) * h
		b -= min(b // 2, p) * 2
		ats += min(b // 2, f) * c
	else:
		ats += min(b // 2, f) * c
		b -= min(b // 2, f) * 2
		ats += min(b // 2, p) * h
	print(ats)


q = int(input())
while q > 0:
	l = list(map(int, input().split()))
	b = l[0]
	p = l[1]
	f = l[2]
	l = list(map(int, input().split()))
	beef_profit = l[0]
	chicken_profit = l[1]
	profit = 0
	burgers = b // 2
	x = max(beef_profit, chicken_profit)
	y = min(beef_profit, chicken_profit)
	a = 0
	b = 0
	if x == beef_profit:
		a = p
		b = f
	else:
		a = f
		b = p
	mini = min(burgers, a)
	profit += mini * x
	burgers -= mini
	mini = min(burgers, b)
	profit += mini * y
	burgers -= mini
	print(profit)
	q -= 1


t = int(input())
for _ in range(t):
	(b, f, p) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		if b % 2 == 0:
			pass
		else:
			b = b - 1
		if 2 * p <= b:
			b = b - 2 * p
			ans = c * p
			if 2 * f <= b:
				ans += h * f
			else:
				ans += h * b // 2
		else:
			ans = c * b // 2
			b = 0
	else:
		if b % 2 == 0:
			pass
		else:
			b = b - 1
		if 2 * f <= b:
			b = b - 2 * f
			ans = h * f
			if 2 * p <= b:
				ans += c * p
			else:
				ans += c * b // 2
		else:
			ans = h * b // 2
			b = 0
	print(ans)


TC = int(input())
for t in range(0, TC):
	(B, P, F) = map(int, input().split())
	if B % 2 == 1:
		B = B - 1
	(H, C) = map(int, input().split())
	ans = 0
	if H > C:
		(H, C) = (C, H)
		(P, F) = (F, P)
	take = min(B // 2, F)
	B = B - 2 * take
	F = F - take
	ans = ans + take * C
	take = min(B // 2, P)
	B = B - 2 * take
	P = P - take
	ans = ans + take * H
	print(ans)


t = int(input())
while t:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	cost = 0
	if b < 1:
		print(0)
	else:
		if h > c:
			cost = cost + min(b, p) * h
			b = b - p
			if b > 0:
				cost += min(b, f) * c
		else:
			cost = cost + min(b, f) * c
			b = b - f
			if b > 0:
				cost += min(b, p) * h
		print(cost)
	t = t - 1


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	if b % 2 != 0:
		b -= 1
	(h, c) = map(int, input().split())
	o = 0
	if h >= c:
		if p * 2 <= b:
			o += p * h
			b -= p * 2
			if f * 2 <= b:
				o += f * c
			else:
				o += b // 2 * c
		else:
			o += b // 2 * h
	elif f * 2 <= b:
		o += f * c
		b -= f * 2
		if p * 2 <= b:
			o += p * h
		else:
			o += b // 2 * h
	else:
		o += b // 2 * c
	print(o)


n = int(input())
for i in range(0, n):
	(b, p, f) = input().split()
	(H, C) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	H = int(H)
	C = int(C)
	if b < 2:
		print(0)
		continue
	if 2 * p + 2 * f < b:
		print(p * H + f * C)
	if H >= C:
		if 2 * p <= b:
			if 2 * f >= b - 2 * p:
				print(p * H + C * int((b - 2 * p) / 2))
				continue
		else:
			print(int(b / 2) * H)
			continue
	if C > H:
		if 2 * f <= b:
			if 2 * p >= b - 2 * f:
				print(f * C + H * int((b - 2 * f) / 2))
				continue
		else:
			print(int(b / 2) * C)
			continue


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	count = 0
	if h >= c:
		b = b // 2
		if b <= p:
			count += h * b
		else:
			count += h * p
			b -= p
			Min = min(b, f)
			count += c * Min
	else:
		b = b // 2
		if b <= f:
			count += c * b
		else:
			count += c * f
			b -= f
			Min = min(b, p)
			count += h * Min
	print(count)


t = int(input())
q = []
for i in range(t):
	l = list(input().split())
	r = list(input().split())
	b = int(l[0])
	p = int(l[1])
	f = int(l[2])
	h = int(r[0])
	c = int(r[1])
	if h >= c:
		if b // 2 <= p:
			q.append(h * (b // 2))
		elif (b - 2 * p) // 2 <= f:
			q.append(h * p + c * ((b - 2 * p) // 2))
		else:
			q.append(h * p + c * f)
	elif b // 2 <= f:
		q.append(c * (b // 2))
	elif (b - 2 * f) // 2 <= p:
		q.append(c * f + h * ((b - 2 * f) // 2))
	else:
		q.append(c * f + h * p)
for i in q:
	print(i)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(b, p, f) = LI()
		(h, c) = LI()
		if c > h:
			(c, h) = (h, c)
			(p, f) = (f, p)
		t = min(p, b // 2)
		r = t * h
		b -= t * 2
		t = min(f, b // 2)
		r += t * c
		rr.append(r)
	return JA(rr, '\n')
print(main())


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		(b, p, f) = get_ints()
		(h, c) = get_ints()
		if h > c:
			ans = min(b // 2, p)
			b -= ans * 2
			ans *= h
			if b > 0:
				ans += c * min(b // 2, f)
			print(ans)
		else:
			ans = min(b // 2, f)
			b -= ans * 2
			ans *= c
			if b > 0:
				ans += h * min(b // 2, p)
			print(ans)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


q = int(input())
for qq in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	x = b // 2
	if b <= 1:
		res = 0
	elif h > c:
		a = min(x, p)
		res = a * h + min(x - a, f) * c
	else:
		a = min(x, f)
		res = a * c + min(x - a, p) * h
	print(res)


t = int(input())
for _ in range(t):
	(b, p, q) = map(int, str(input()).split())
	(h, c) = map(int, str(input()).split())
	s = 0
	if h > c:
		(h, c) = (c, h)
		(p, q) = (q, p)
	if b < 2 * q:
		print(c * (b // 2))
	else:
		s += c * q
		b = b - q * 2
		if b < 2 * p:
			s += h * (b // 2)
			print(s)
		else:
			s += h * p
			print(s)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(b, p, f) = rints()
	(h, c) = rints()
	if h >= c:
		nh = min(b // 2, p)
		prof = h * nh + c * min((b - 2 * nh) // 2, f)
	else:
		nc = min(b // 2, f)
		prof = c * nc + h * min((b - 2 * nc) // 2, p)
	print(prof)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	cost = 0
	if h < c:
		while b > 1 and f > 0:
			cost += c
			b -= 2
			f -= 1
		while b > 1 and p > 0:
			cost += h
			b -= 2
			p -= 1
	else:
		while b > 1 and p > 0:
			cost += h
			b -= 2
			p -= 1
		while b > 1 and f > 0:
			cost += c
			b -= 2
			f -= 1
	print(cost)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b >>= 1
	if h > c:
		k1 = min(b, p)
		k2 = min(b - k1, f)
	else:
		k2 = min(b, f)
		k1 = min(b - k2, p)
	print(k1 * h + k2 * c)


n = int(input())
while n:
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	x = b // 2
	ans = 0
	if h < c:
		ans = min(x, f) * c
		x = max(x - f, 0)
		ans += min(x, p) * h
	else:
		ans = min(x, p) * h
		x = max(x - p, 0)
		ans += min(x, f) * c
	print(ans)
	n -= 1


n = int(input())
for i in range(n):
	count = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		(h, c) = (c, h)
		(p, f) = (f, p)
	b = int(b / 2)
	if b > 0:
		count = count + min(b, p) * h
		b = b - min(b, p)
	if b > 0:
		count = count + min(b, f) * c
		b = b - min(b, f)
	print(count)


F = lambda : map(int, input().split())
for _ in range(int(input())):
	(b, p, f) = F()
	(h, c) = F()
	print(max(min(b // 2, p) * h + c * min(b // 2 - min(b // 2, p), f), min(b // 2, f) * c + h * min(b // 2 - min(b // 2, f), p)))


q = int(input())
for _ in range(q):
	args = input().split(' ')
	for i in range(0, len(args)):
		args[i] = int(args[i])
	b = args[0]
	if b % 2 == 1:
		b -= 1
	p = args[1]
	f = args[2]
	args = input().split(' ')
	for i in range(0, len(args)):
		args[i] = int(args[i])
	h = args[0]
	c = args[1]
	price = 0
	if b // 2 >= p + f:
		print(str(p * h + f * c))
	else:
		while b > 0:
			if h > c:
				if p > 0:
					price += h
					p -= 1
					b -= 2
				elif f > 0:
					price += c
					f -= 1
					b -= 2
				else:
					break
			elif f > 0:
				price += c
				f -= 1
				b -= 2
			elif p > 0:
				price += h
				p -= 1
				b -= 2
			else:
				break
		print(price)


for tt in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pft = 0
	mb = b // 2
	if mb:
		if h > c:
			if p >= mb:
				pft = mb * h
			else:
				pft = p * h
				mb -= p
				if mb >= f:
					pft += f * c
				else:
					pft += mb * c
		elif f >= mb:
			pft = mb * c
		else:
			pft = f * c
			mb -= f
			if mb >= p:
				pft += p * h
			else:
				pft += mb * h
	print(pft)


n = int(input())
for i in range(n):
	arr = list(map(int, input().split(' ')))
	pr = list(map(int, input().split(' ')))
	l = pr.index(max(pr))
	if arr[0] >= arr[1 + l] * 2:
		if arr[0] - arr[1 + l] * 2 >= arr[2 - l] * 2:
			print(pr[l] * arr[1 + l] + pr[1 - l] * arr[2 - l])
		else:
			print(pr[l] * arr[1 + l] + (arr[0] // 2 - arr[1 + l]) * pr[1 - l])
	else:
		print(arr[0] // 2 * pr[l])


import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(B, P, F, H, C):
	tot = B // 2
	ans = 0
	(a, pa, b, pb) = (P, H, F, C)
	if pa < pb:
		(a, pa, b, pb) = (b, pb, a, pa)
	z = 0
	c = min(tot, a)
	z += pa * c
	tot -= c
	c = min(tot, b)
	z += pb * c
	tot -= c
	return z

def main():
	T = int(inp())
	for _ in range(T):
		(B, P, F) = [int(e) for e in inp().split()]
		(H, C) = [int(e) for e in inp().split()]
		print(solve(B, P, F, H, C))
main()


t = int(input())
for w in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	ans = 0
	kol = b // 2
	if h > c:
		if kol > p:
			ans += p * h
			kol -= p
		else:
			ans += kol * h
			kol = 0
		if kol > f:
			ans += f * c
		else:
			ans += kol * c
	else:
		if kol > f:
			ans += f * c
			kol -= f
		else:
			ans += kol * c
			kol = 0
		if kol > p:
			ans += p * h
		else:
			ans += kol * h
	print(ans)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	b //= 2
	resp = 0
	ff = min(b, p)
	b -= ff
	resp += h * ff
	ff = min(b, f)
	resp += c * ff
	print(resp)


t = int(input())
while t:
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	total_buns = b // 2
	total_burger = p + f
	while True:
		if total_buns >= total_burger:
			if f < 0:
				p = p + f
				f = 0
			elif p < 0:
				f = f + p
				p = 0
			profit = c * f + h * p
			break
		elif h > c:
			f -= 1
		else:
			p -= 1
		total_burger = f + p
	print(profit)
	t -= 1


a = int(input())
r = 0
b = list()
while r < a:
	c = [int(c) for c in input().split()]
	d = [int(d) for d in input().split()]
	if c[0] == 1:
		b.append(0)
	elif 2 * (c[1] + c[2]) <= c[0]:
		b.append(d[0] * c[1] + d[1] * c[2])
	elif d[0] > d[1]:
		if 2 * c[1] >= c[0]:
			b.append(c[0] // 2 * d[0])
		else:
			b.append(c[1] * d[0] + d[1] * ((c[0] - 2 * c[1]) // 2))
	elif 2 * c[2] >= c[0]:
		b.append(c[0] // 2 * d[1])
	else:
		b.append(c[2] * d[1] + d[0] * ((c[0] - 2 * c[2]) // 2))
	r = r + 1
r = 0
while r < len(b):
	print(b[r])
	r = r + 1


for i in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	mc = 0
	if h > c:
		mc += h * min(b // 2, p)
		(b, p) = (b - 2 * min(b // 2, p), p - min(b // 2, p))
		mc += c * min(b // 2, f)
	else:
		mc += c * min(b // 2, f)
		(b, f) = (b - 2 * min(b // 2, f), p - min(b // 2, f))
		mc += h * min(b // 2, p)
	print(mc)


for _ in range(int(input())):
	(b, m, k) = map(int, input().split())
	(pm, pk) = map(int, input().split())
	if pm < pk:
		(m, k) = (k, m)
		(pm, pk) = (pk, pm)
	b //= 2
	x = min(b, m)
	b -= x
	res = x * pm
	x = min(b, k)
	res += x * pk
	print(res)


t = int(input())
for i in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	if h >= c:
		if b // 2 <= p:
			s = b // 2 * h
		else:
			s = p * h + min((b - p * 2) // 2, f) * c
	elif b // 2 <= f:
		s = b // 2 * c
	else:
		s = f * c + min((b - f * 2) // 2, p) * h
	print(s)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	price = 0
	z = 0
	if b == 1 or b == 0:
		print(0)
		continue
	elif p + f > int(b / 2):
		if h > c:
			if int(b / 2) - p <= 0:
				print(int(b / 2) * h)
				continue
			else:
				price = (int(b / 2) - p) * c + p * h
		elif int(b / 2) - f <= 0:
			print(int(b / 2) * c)
			continue
		else:
			price = (int(b / 2) - f) * h + f * c
	else:
		price = f * c + p * h
	print(price)


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	for i in range(0, p + 1):
		for j in range(0, f + 1):
			if i + j + i + j <= b:
				ans = max(ans, i * h + j * c)
	print(ans)
	t -= 1


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	b //= 2
	if h > c:
		if b < p:
			print(h * b)
		else:
			b -= p
			print(h * p + min(b, f) * c)
	elif b < f:
		print(c * b)
	else:
		b -= f
		print(f * c + min(b, p) * h)


case = int(input())
for _ in list(range(case)):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(y) for y in input().split()]
	profit = 0
	if c >= h:
		cost1 = c
		stff1 = f
		cost2 = h
		stff2 = p
	elif h > c:
		cost1 = h
		stff1 = p
		cost2 = c
		stff2 = f
	while stff1 != 0 and b > 1:
		profit += cost1
		stff1 -= 1
		b -= 2
	while stff2 != 0 and b > 1:
		profit += cost2
		stff2 -= 1
		b -= 2
	print(profit)


x = int(input())
for i in range(x):
	(b, p, c) = map(int, input().split())
	k = b // 2
	profit = []
	(m, n) = map(int, input().split())
	if b < 2:
		print('0')
	elif k >= p + c:
		a = p * m + c * n
		print(a)
	elif k < p + c and k > p and (k > c):
		d = c * n + (k - c) * m
		print(d)
	elif k < p + c and k <= c and (k > p):
		f = k * n
		print(max(p * m + (k - p) * n, f))
	elif k < p + c and k <= p and (k > c):
		g = k * m
		print(max(c * n + (k - c) * m, g))
	elif p >= k or c >= k:
		e = k * max(m, n)
		print(e)


t = int(input())

def foo(b, p, f, h, c):
	k = 0
	if c > h:
		if b >= 2 * f:
			b -= 2 * f
			k += f * c
			f = 0
		else:
			k += c * (b // 2)
			f -= b // 2
			b = 0
		if b >= 2 * p:
			b -= 2 * p
			k += p * h
			p = 0
		else:
			k += h * (b // 2)
			p -= b // 2
			b -= b // 2
	else:
		if b >= 2 * p:
			b -= 2 * p
			k += p * h
			p = 0
		else:
			k += h * (b // 2)
			p -= b // 2
			b = 0
		if b >= 2 * f:
			b -= 2 * f
			k += f * c
			f = 0
		else:
			k += c * (b // 2)
			f -= b // 2
			b -= b // 2
	return k
for i in range(t):
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	print(foo(b, p, f, h, c))


a = int(input())
ans = 0
add = list()

def computing(b, p, f, h, c, ans):
	if b < 2:
		return ans
	elif c >= h:
		while f > 0 and b > 1:
			b = b - 2
			f = f - 1
			ans = ans + c
		while p > 0 and b > 1:
			b = b - 2
			p = p - 1
			ans = ans + h
		return ans
	elif h > c:
		while p > 0 and b > 1:
			b = b - 2
			p = p - 1
			ans = ans + h
		while f > 0 and b > 1:
			b = b - 2
			f = f - 1
			ans = ans + c
		return ans
for i in range(0, a):
	(b, p, f) = [int(b) for b in input().split()]
	(h, c) = [int(h) for h in input().split()]
	add = add + [computing(b, p, f, h, c, ans)]
for i in add:
	print(i)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	num_of_hamburgers = 0
	num_of_chickenburgers = 0
	b = b // 2
	if h > c:
		if b >= p:
			b -= p
			num_of_hamburgers = p
		else:
			num_of_hamburgers = b
			b = 0
		if b >= f:
			b -= f
			num_of_chickenburgers = f
		else:
			num_of_chickenburgers = b
			b = 0
	elif h < c:
		if b >= f:
			b -= f
			num_of_chickenburgers = f
		else:
			num_of_chickenburgers = b
			b = 0
		if b >= p:
			b -= p
			num_of_hamburgers = p
		else:
			num_of_hamburgers = b
			b = 0
	elif p > f:
		if b >= p:
			b -= p
			num_of_hamburgers = p
		else:
			num_of_hamburgers = b
			b = 0
		if b >= f:
			b -= f
			num_of_chickenburgers = f
		else:
			num_of_chickenburgers = b
			b = 0
	else:
		if b >= f:
			b -= f
			num_of_chickenburgers = f
		else:
			num_of_chickenburgers = b
			b = 0
		if b >= p:
			b -= p
			num_of_hamburgers = p
		else:
			num_of_hamburgers = b
			b = 0
	print(num_of_hamburgers * h + num_of_chickenburgers * c)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	s = 0
	if b > 0:
		if h >= c:
			if b < p:
				s = s + h * b
			else:
				s = s + h * p
				b = b - p
				if b < f:
					s = s + c * b
				else:
					s = s + c * f
		elif b < f:
			s = s + c * b
		else:
			s = s + c * f
			b = b - f
			if b < p:
				s = s + h * b
			else:
				s = s + h * p
	print(s)


def f():
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	a = 0
	if b >= (p + f) * 2:
		return p * h + f * c
	elif b <= 1:
		return 0
	elif c > h:
		while b > 1 and f > 0:
			a += c
			b -= 2
			f -= 1
		while b > 1 and p > 0:
			a += h
			b -= 2
			p -= 1
	else:
		while b > 1 and p > 0:
			a += h
			b -= 2
			p -= 1
		while b > 1 and f > 0:
			a += c
			b -= 2
			f -= 1
	return a
n = int(input())
re = []
for i in range(0, n):
	re.append(f())
for i in re:
	print(i)


n = int(input())
outputs = []
for i in range(n):
	inputs = input().split(' ')
	for j in range(len(inputs)):
		inputs[j] = int(inputs[j])
	prices = input().split(' ')
	for k in range(len(prices)):
		prices[k] = int(prices[k])
	if inputs[0] >= 2 * (inputs[1] + inputs[2]):
		outputs.append(inputs[1] * prices[0] + inputs[2] * prices[1])
	elif prices[0] > prices[1]:
		sum = 0
		b = inputs[0] // 2
		sum += min(inputs[1], b) * prices[0]
		b -= min(inputs[1], b)
		sum += min(inputs[2], b) * prices[1]
		outputs.append(sum)
	else:
		sum = 0
		b = inputs[0] // 2
		sum += min(inputs[2], b) * prices[1]
		b -= min(inputs[2], b)
		sum += min(inputs[1], b) * prices[0]
		outputs.append(sum)
for i in range(n):
	print(outputs[i])


import math
case = int(input())
for caseNum in range(0, case):
	(buns, a, b) = [int(x) for x in input().split()]
	(xD, yD) = [int(x) for x in input().split()]
	if xD >= yD:
		first = min(math.floor(buns / 2), a)
		second = min(math.floor((buns - first * 2) / 2), b)
	else:
		second = min(math.floor(buns / 2), b)
		first = min(math.floor((buns - second * 2) / 2), a)
	print(first * xD + second * yD)


t = int(input())
s = 0
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	k = b // 2
	if h > c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	while k > 0 and f > 0:
		s += c
		k -= 1
		f -= 1
	while k > 0 and p > 0:
		s += h
		k -= 1
		p -= 1
	print(s)
	s = 0


(x, y) = (0, 0)
for i in range(int(input())):
	(a, b, c) = [int(aa) for aa in input().split()]
	(d, e) = [int(bb) for bb in input().split()]
	a //= 2
	if d < e:
		(d, e) = (e, d)
		(b, c) = (c, b)
	x = min(a, b)
	a -= x
	y = min(a, c)
	print(x * d + y * e)


n = int(input())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	c1 = 0
	h1 = 0
	bun = b // 2
	if c > h:
		for i in range(f):
			if bun > 0:
				c1 += 1
				bun -= 1
		for i in range(p):
			if bun > 0:
				h1 += 1
				bun -= 1
	else:
		for i in range(p):
			if bun > 0:
				h1 += 1
				bun -= 1
		for i in range(f):
			if bun > 0:
				c1 += 1
				bun -= 1
	print(h1 * h + c1 * c)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if b < 2:
		print(0)
	elif h > c:
		hamburgers = min(b // 2, p)
		b -= hamburgers * 2
		p -= hamburgers
		chickenBurgers = min(b // 2, f)
		print(hamburgers * h + chickenBurgers * c)
	elif h < c:
		chickenBurgers = min(b // 2, f)
		b -= chickenBurgers * 2
		f -= chickenBurgers
		hamburgers = min(b // 2, p)
		print(hamburgers * h + chickenBurgers * c)
	else:
		chickenBurgers = min(b // 2, f)
		b -= chickenBurgers * 2
		f -= chickenBurgers
		hamburgers = min(b // 2, p)
		print(hamburgers * h + chickenBurgers * c)


test = int(input())
for _ in range(test):
	maxOut = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	if h == c:
		p = p + f
		if b < 2 * p:
			maxOut = b // 2 * h
		else:
			maxOut = p * h
	elif b < 2 * p:
		maxOut = b // 2 * h
	else:
		maxOut = p * h
		b -= 2 * p
		if b < 2 * f:
			maxOut += b // 2 * c
		else:
			maxOut += c * f
	print(maxOut)


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	P = sorted([(h, p), (c, f)], reverse=True)
	S = 0
	for element in P:
		(r, q) = element
		n = min(b // 2, q)
		b -= 2 * n
		S += r * n
	print(S)


def getprofit(buns, item1, item2, price1, price2):
	item1count = 0
	item2count = 0
	while buns != 0 and item1 != 0:
		item1 -= 1
		buns -= 2
		item1count += 1
	while buns != 0 and item2 != 0:
		item2 -= 1
		buns -= 2
		item2count += 1
	return item1count * price1 + item2count * price2
t = int(input())
while t:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b % 2 != 0:
		b -= 1
	if h > c:
		profit = getprofit(b, p, f, h, c)
	else:
		profit = getprofit(b, f, p, c, h)
	print(profit)
	t -= 1


for _ in range(int(input())):
	bpf = list(map(int, input().split()))
	b = bpf[0]
	p = bpf[1]
	f = bpf[2]
	r = 0
	hc = list(map(int, input().split()))
	h = hc[0]
	c = hc[1]
	if b < 2:
		print(0)
	else:
		if h < c:
			if b // 2 >= f:
				r = r + c * f
				b = b - f * 2
			else:
				r = r + b // 2 * c
				b = b - b // 2 * 2
			if b // 2 >= p:
				r = r + h * p
				b = b - p * 2
			else:
				r = r + b // 2 * h
				b = b - b // 2 * 2
		else:
			if b // 2 >= p:
				r = r + h * p
				b = b - p * 2
			else:
				r = r + b // 2 * h
				b = b - b // 2 * 2
			if b // 2 >= f:
				r = r + c * f
				b = b - f * 2
			else:
				r = r + b // 2 * c
				b = b - b // 2 * 2
		print(r)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b > 1:
		if h >= c:
			ans = 0
			for i in range(1, b + 1):
				if b < 2:
					break
				elif p != 0:
					p -= 1
					b -= 2
					ans += h
				elif p == 0 and f != 0:
					f -= 1
					b -= 2
					ans += c
			print(ans)
		elif h < c:
			ans = 0
			for i in range(1, b + 1):
				if b < 2:
					break
				elif f != 0:
					f -= 1
					b -= 2
					ans += c
				elif f == 0 and p != 0:
					p -= 1
					b -= 2
					ans += h
			print(ans)
	else:
		print(0)


n = int(input())
a = []
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	sum = 0
	if c > h:
		maximum = f
		minimum = p
	else:
		maximum = p
		minimum = f
	dollars = max(c, h)
	while b > 1 and maximum > 0:
		sum += dollars
		b -= 2
		maximum -= 1
	dollars = min(c, h)
	while b > 1 and minimum > 0:
		sum += dollars
		b -= 2
		minimum -= 1
	a.append(sum)
print(*a, sep='\n')


for _ in range(int(input())):
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	tot = 0
	if h > c:
		br = min(b // 2, p)
		tot += br * h
		b -= 2 * br
		br = min(b // 2, f)
		tot += br * c
	else:
		br = min(b // 2, f)
		tot += br * c
		b -= 2 * br
		br = min(b // 2, p)
		tot += br * h
	print(tot)


t = int(input())
for i in range(t):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(min(a[0] // 2, a[b.index(max(b)) + 1]) * max(b) + min(max(a[0] // 2 - a[b.index(max(b)) + 1], 0), a[b.index(min(b)) + 1]) * min(b))


t = int(input())
bpf = []
hc = []
while t > 0:
	bpf = [int(x) for x in input().split(' ')]
	hc = [int(x) for x in input().split(' ')]
	tot = 0
	bpf[0] = int(bpf[0] / 2)
	if bpf[0] >= bpf[1] + bpf[2]:
		tot = bpf[2] * hc[1] + bpf[1] * hc[0]
	elif hc[1] >= hc[0]:
		if bpf[0] >= bpf[2]:
			tot += bpf[2] * hc[1]
			bpf[0] = bpf[0] - bpf[2]
			if bpf[0] >= bpf[1]:
				tot += bpf[1] * hc[0]
			else:
				tot += bpf[0] * hc[0]
		else:
			tot += bpf[0] * hc[1]
	elif bpf[0] >= bpf[1]:
		tot += bpf[1] * hc[0]
		bpf[0] = bpf[0] - bpf[1]
		if bpf[0] >= bpf[2]:
			tot += bpf[2] * hc[1]
		else:
			tot += bpf[0] * hc[1]
	else:
		tot += bpf[0] * hc[0]
	print(tot)
	t -= 1


test_case = int(input())
for _ in range(test_case):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	bun = b // 2
	if bun < 1:
		print(0)
		continue
	maximum = max(h, c)
	if maximum == c:
		profit = min(bun, f) * c + min(p, max(0, bun - f)) * h
	else:
		profit = min(bun, p) * h + min(f, max(0, bun - p)) * c
	print(profit)


counter = int(input())
while counter:
	counter -= 1
	(bun, ham, chkn) = map(int, input().split(' '))
	bun = bun // 2
	tot_cost = 0
	(ham_prize, chkn_prize) = [int(i) for i in input().split(' ')]
	if ham_prize > chkn_prize:
		tot_cost += ham_prize * min(ham, bun)
		bun -= ham
		if bun > 0:
			tot_cost += chkn_prize * min(bun, chkn)
	else:
		tot_cost += chkn_prize * min(chkn, bun)
		bun -= chkn
		if bun > 0:
			tot_cost += ham_prize * min(ham, bun)
	print(tot_cost)


n = int(input())
for i in range(n):
	s = 0
	(a, b, c) = map(int, input().split())
	(h, f) = map(int, input().split())
	if h > f:
		while a > 1 and b > 0:
			a -= 2
			b -= 1
			s += h
		while a > 1 and c > 0:
			a -= 2
			c -= 1
			s += f
	else:
		while a > 1 and c > 0:
			a -= 2
			c -= 1
			s += f
		while a > 1 and b > 0:
			a -= 2
			b -= 1
			s += h
	print(s)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	if h < c:
		(p, f, h, c) = (f, p, c, h)
	x = min(b, p)
	y = min(b - x, f)
	print(x * h + y * c)


t = int(input())
b = [0 for i in range(t)]
p = [0 for i in range(t)]
f = [0 for i in range(t)]
h = [0 for i in range(t)]
c = [0 for i in range(t)]
total = [0 for i in range(t)]
for i in range(t):
	(b[i], p[i], f[i]) = input().split()
	(h[i], c[i]) = input().split()
i = 0
for i in range(t):
	b[i] = int(b[i])
	p[i] = int(p[i])
	f[i] = int(f[i])
	h[i] = int(h[i])
	c[i] = int(c[i])
for i in range(t):
	total[i] = 0
	if h[i] > c[i]:
		while b[i] > 1 and p[i] > 0:
			b[i] -= 2
			p[i] -= 1
			total[i] += h[i]
		while b[i] > 1 and f[i] > 0:
			b[i] -= 2
			f[i] -= 1
			total[i] += c[i]
	else:
		while b[i] > 1 and f[i] > 0:
			b[i] -= 2
			f[i] -= 1
			total[i] += c[i]
		while b[i] > 1 and p[i] > 0:
			b[i] -= 2
			p[i] -= 1
			total[i] += h[i]
	print(total[i])


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(n, m) = map(int, input().split())
	pr = 0
	if n >= m:
		q = min(a // 2, b)
		a = a - q * 2
		b = b - q
		pr = pr + n * q
		w = min(a // 2, c)
		a = a - w * 2
		c = c - w
		pr = pr + w * m
		print(pr)
	else:
		w = min(a // 2, c)
		a = a - w * 2
		c = c - w
		pr = pr + w * m
		q = min(a // 2, b)
		a = a - q * 2
		b = b - q
		pr = pr + n * q
		print(pr)


for _ in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	sams = b // 2
	ans = 0
	if h > c:
		pats = min(sams, p)
		sams -= pats
		ans += pats * h
		fats = min(sams, f)
		ans += fats * c
	else:
		fats = min(sams, f)
		sams -= fats
		ans += fats * c
		pats = min(sams, p)
		ans += pats * h
	print(ans)


import math

def solve(b, p, f, h, c):
	expensive = 0
	cheap = 0
	expPatties = 0
	cheapPatties = 0
	if h >= c:
		expensive = h
		expPatties = p
		cheap = c
		cheapPatties = f
	else:
		expensive = c
		expPatties = f
		cheap = h
		cheapPatties = p
	if b / 2 < expPatties:
		return math.floor(b / 2) * expensive
	profit = expPatties * expensive
	b -= expPatties * 2
	profit += min(math.floor(b / 2), cheapPatties) * cheap
	return profit
nrQuerries = int(input())
for i in range(nrQuerries):
	(b, p, f) = map(lambda x: int(x), input().strip().split())
	(h, c) = map(lambda x: int(x), input().strip().split())
	print(solve(b, p, f, h, c))


t = int(input())
s = []
for i in range(0, t):
	x = input()
	xx = x.split()
	b = int(xx[0])
	if b % 2 == 1:
		b -= 1
	p = int(xx[1])
	f = int(xx[2])
	x = input()
	xx = x.split()
	h = float(xx[0])
	c = float(xx[1])
	g = 0
	if h > c:
		if b > 2 * p:
			g = g + p * h
			b -= 2 * p
			if b > f * 2:
				g = g + f * c
			else:
				g = g + b * c / 2
		else:
			g = g + b * h / 2
	elif b > 2 * f:
		g = g + f * c
		b -= 2 * f
		if b > p * 2:
			g = g + p * h
		else:
			g = g + b * h / 2
	else:
		g = g + b * c / 2
	s.append(g)
for i in s:
	print(int(i))


q = int(input())
for i in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c >= h:
		profit = 0
		while b > 1 and f > 0:
			b = b - 2
			f = f - 1
			profit += c
		while b > 1 and p > 0:
			b = b - 2
			p = p - 1
			profit += h
	else:
		profit = 0
		while b > 1 and p > 0:
			b = b - 2
			p = p - 1
			profit += h
		while b > 1 and f > 0:
			b = b - 2
			f = f - 1
			profit += c
	print(profit)


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	r = 0
	b = b // 2
	cn = min(b, p)
	b -= cn
	p -= cn
	r += cn * h
	cn = min(b, f)
	b -= cn
	f -= cn
	r += cn * c
	print(r)
	t = t - 1


for _ in range(int(input())):
	(b, h, c) = map(int, input().split())
	(p1, p2) = map(int, input().split())
	if p1 >= p2:
		a = min(h, b // 2)
		b -= 2 * a
		a = a * p1
		b = min(c, b // 2) * p2
		print(a + b)
	else:
		a = min(c, b // 2)
		b -= 2 * a
		a = a * p2
		b = min(h, b // 2) * p1
		print(a + b)


f = lambda : map(int, input().split())
for _ in range(int(input())):
	(a, b, c) = f()
	(c1, c2) = f()
	d = sorted([[c1, b], [c2, c]], reverse=True)
	d1 = min(d[0][1], a // 2)
	d2 = min(d[1][1], (a - 2 * d1) // 2)
	print(d1 * d[0][0] + d2 * d[1][0])


n = int(input())
for _ in range(n):
	x = [int(i) for i in input().split()]
	(b, p, f) = (x[0], x[1], x[2])
	y = [int(i) for i in input().split()]
	(h, c) = (y[0], y[1])
	m = int(b / 2)
	if h == c:
		print(min(m, p + f) * h)
	elif h > c:
		print(p * h + min(m - p, f) * c if m >= p else m * h)
	else:
		print(f * c + min(m - f, p) * h if m >= f else m * c)


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
for _ in range(int(f_input())):
	(bun, beef, chicken) = map(int, f_input().split())
	(beefburger, chickenburger) = map(int, f_input().split())
	(total, max_beef, max_chicken) = (bun // 2, beefburger * beef, chickenburger * chicken)
	if total >= beef + chicken:
		f_print(str(max_beef + max_chicken) + '\n')
		continue
	profit = 0
	if chickenburger > beefburger:
		if chicken >= total:
			profit = chickenburger * min(chicken, total)
		else:
			profit = chickenburger * chicken + beefburger * (total - chicken)
	elif beef >= total:
		profit = beefburger * min(beef, total)
	else:
		profit = beefburger * beef + chickenburger * (total - beef)
	f_print(str(profit) + '\n')


t = int(input())
for tt in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h > c:
		hn = min([b // 2, p])
		cn = min([(b - hn * 2) // 2, f])
	else:
		cn = min([b // 2, f])
		hn = min([(b - cn * 2) // 2, p])
	print(h * hn + c * cn)


def magic(arr, ceni):
	price = 0
	b = arr[0]
	p = arr[1]
	f = arr[2]
	h = ceni[0]
	c = ceni[1]
	if h > c:
		while b >= 2 and p >= 1:
			price += h
			b -= 2
			p -= 1
		while b >= 2 and f >= 1:
			price += c
			b -= 2
			f -= 1
	else:
		while b >= 2 and f >= 1:
			price += c
			b -= 2
			f -= 1
		while b >= 2 and p >= 1:
			price += h
			b -= 2
			p -= 1
	return price
n = int(input())
arr = []
for i in range(2 * n):
	k = list(map(int, input().split(' ')))
	arr.append(k)
i = 0
while i != len(arr):
	print(magic(arr[i], arr[i + 1]))
	i += 2


x = int(input())
for i in range(x):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	t = b // 2
	tc = 0
	if h > c:
		if p > t:
			tc += t * h
		else:
			tc = p * h
			t = t - p
			if t > f:
				tc += f * c
			else:
				tc += t * c
	elif f > t:
		tc += t * c
	else:
		tc = f * c
		t = t - f
		if t > p:
			tc += p * h
		else:
			tc += t * h
	print(tc)


t = int(input())
for i in range(t):
	x = 0
	y = 0
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	if d > e:
		for j in range(1, b + 1):
			if j * 2 <= a:
				x += 1
		a = a - x * 2
		for j in range(1, c + 1):
			if j * 2 <= a:
				y += 1
		print(x * d + y * e)
	elif d < e:
		for j in range(1, c + 1):
			if j * 2 <= a:
				x += 1
		a = a - x * 2
		for j in range(1, b + 1):
			if j * 2 <= a:
				y += 1
		print(x * e + y * d)
	elif d == e:
		if b > c:
			for j in range(1, b + 1):
				if j * 2 <= a:
					x += 1
			a = a - x * 2
			for j in range(1, c + 1):
				if j * 2 <= a:
					y += 1
			print(x * d + y * d)
		elif b < c:
			for j in range(1, c + 1):
				if j * 2 <= a:
					x += 1
			a = a - x * 2
			for j in range(1, b + 1):
				if j * 2 <= a:
					y += 1
			print(x * d + y * d)
		elif b == c:
			for j in range(1, b + 1):
				if j * 2 <= a:
					x += 1
			a = a - x * 2
			for j in range(1, c + 1):
				if j * 2 <= a:
					y += 1
			print(x * d + y * d)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(b, p, f) = nm()
	(h, c) = nm()
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	ans = 0
	hc = min(b // 2, p)
	b -= hc * 2
	ans += hc * h
	cc = min(b // 2, f)
	ans += cc * c
	print(ans)
	return
T = ni()
for _ in range(T):
	solve()


t = int(input())
for i in range(t):
	(bulki, gov, kur) = map(int, input().split())
	bulki //= 2
	(gamb, chix) = map(int, input().split())
	price = 0
	if gamb > chix:
		b = min(bulki, gov)
		price += b * gamb
		bulki -= b
		gov -= b
		price += min(bulki, kur) * chix
		print(price)
	elif gamb < chix:
		b = min(bulki, kur)
		price += b * chix
		bulki -= b
		kur -= b
		price += min(bulki, gov) * gamb
		print(price)
	elif gamb == chix:
		price += gamb * min(bulki, gov + kur)
		print(price)


def IL():
	return map(int, input().split())

def IS():
	return int(input())
T = IS()
for _ in range(T):
	(B, P, F) = IL()
	(H, C) = IL()
	profit = 0
	if H < C:
		(H, C) = (C, H)
		(P, F) = (F, P)
	while B > 1:
		if P > 0:
			P -= 1
			B -= 2
			profit += H
		else:
			break
	while B > 1:
		if F > 0:
			F -= 1
			B -= 2
			profit += C
		else:
			break
	print(profit)


for t in range(int(input())):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	res = 0
	if h > c:
		res += h * min(b // 2, p)
		b -= min(b // 2, p) * 2
		res += c * min(b // 2, f)
	else:
		res += c * min(b // 2, f)
		b -= min(b // 2, f) * 2
		res += h * min(b // 2, p)
	print(res)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
t = c.cin()
for i in range(t):
	b = c.cin()
	p = c.cin()
	cc = c.cin()
	pp = c.cin()
	pc = c.cin()
	b = b // 2
	tot = 0
	if pp > pc:
		nb = min(p, b)
		tot += pp * nb
		if b - nb >= 0:
			tot += min(b - nb, cc) * pc
	else:
		nb = min(cc, b)
		tot += pc * nb
		if b - nb >= 0:
			tot += min(b - nb, p) * pp
	print(tot)


for i in range(int(input())):
	(n, f, c) = map(int, input().split())
	(h, ck) = map(int, input().split())
	if n % 2 == 1:
		n = n - 1
	p = 0
	if h > ck:
		if n > 2 * f:
			p = p + h * f
			n = n - 2 * f
			if n > 2 * c:
				p = p + ck * c
			else:
				p = p + ck * (n // 2)
			print(p)
		else:
			p = p + h * (n // 2)
			print(p)
	else:
		t = f
		f = c
		c = t
		t = h
		h = ck
		ck = t
		if n > 2 * f:
			p = p + h * f
			n = n - 2 * f
			if n > 2 * c:
				p = p + ck * c
			else:
				p = p + ck * (n // 2)
			print(p)
		else:
			p = p + h * (n // 2)
			print(p)


def main():
	t = int(input())
	for i in range(t):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		b = b // 2
		if h >= c:
			x = min(b, p)
			b -= x
			ans = h * x
			ans += min(b, f) * c
			print(ans)
		else:
			x = min(b, f)
			b -= x
			ans = c * x
			ans += min(b, p) * h
			print(ans)
main()


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if b == 1:
		profit = 0
	elif b // 2 > p + f:
		profit = p * h + f * c
	else:
		x = b // 2
		if h > c and p <= x:
			profit = p * h + c * (x - p)
		elif h < c and f <= x:
			profit = c * f + h * (x - f)
		elif h > c and p > x:
			profit = x * h
		else:
			profit = x * c
	print(profit)
	t -= 1


for q in range(int(input())):
	(x, y, z) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h < c:
		(y, z, h, c) = (z, y, c, h)
	if x <= y * 2:
		print(x // 2 * h)
	else:
		print(y * h + min((x - 2 * y) // 2, z) * c)


t = int(input())
for i in range(t):
	(b, p, f) = [int(x) for x in str(input()).split()]
	b = b // 2
	(h, c) = [int(x) for x in str(input()).split()]
	profit = 0
	if h > c:
		profit = h * min(b, p)
		m = min(b, p)
		profit = profit + c * min(b - m, f)
	else:
		profit = c * min(b, f)
		m = min(b, f)
		profit = profit + h * min(b - m, p)
	print(profit)


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	(fc, sc) = (p, f) if h >= c else (f, p)
	(fp, sp) = (h, c) if h >= c else (c, h)
	out = 0
	min_fc = min(b // 2, fc)
	out += fp * min_fc
	b -= 2 * min_fc
	min_sc = min(b // 2, sc)
	out += sp * min_sc
	print(out)


n = int(input())
a = []
for i in range(n):
	money = 0
	(b, p, f) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	(h, c) = input().split()
	h = int(h)
	c = int(c)
	b = b // 2
	if c > h:
		num1 = min([b, f])
		money += num1 * c
		b -= num1
		num2 = min(b, p)
		money += num2 * h
		a.append(money)
	else:
		num1 = min([b, p])
		money += num1 * h
		b -= num1
		num2 = min(b, f)
		money += num2 * c
		a.append(money)
for num in a:
	print(num)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	income = 0
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	count = min(b, p)
	b -= count
	income += count * h
	count = min(b, f)
	b -= count
	income += count * c
	print(income)


t = int(input())
answer = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if h > c:
		while b > 1 and p > 0:
			profit += h
			b -= 2
			p -= 1
		while b > 1 and f > 0:
			profit += c
			b -= 2
			f -= 1
	else:
		while b > 1 and f > 0:
			profit += c
			b -= 2
			f -= 1
		while b > 1 and p > 0:
			profit += h
			b -= 2
			p -= 1
	answer.append(profit)
for item in answer:
	print(item)


for _ in range(int(input())):
	(b, p, f) = (int(s) for s in input().split())
	(h, c) = (int(s) for s in input().split())
	b = b // 2
	ans = 0
	if h > c:
		ans += min(b, p) * h
		b = b - min(b, p)
		ans += min(b, f) * c
	else:
		ans += min(b, f) * c
		b = b - min(b, f)
		ans += min(b, p) * h
	print(ans)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	a = min(b // 2, p if h > c else f)
	d = min((b - 2 * a) // 2, p if h < c else f)
	print(max(h, c) * a + min(h, c) * d)


from sys import stdin, stdout
t = int(stdin.readline())
while t != 0:
	t -= 1
	(b, p, f) = [int(x) for x in stdin.readline().split()]
	(h, c) = [int(x) for x in stdin.readline().split()]
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	ans = min(b // 2, p) * h
	b -= min(b // 2, p) * 2
	ans += min(b // 2, f) * c
	stdout.write(str(ans) + '\n')


for _ in range(int(input())):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	mx = 0
	brgs = 0
	while 2 * brgs <= b and brgs <= p:
		rmbns = b - 2 * brgs
		chcks = min(rmbns // 2, f)
		mx = max(mx, brgs * h + chcks * c)
		brgs += 1
	print(mx)


test = int(input())
while test > 0:
	test -= 1
	(buns, beef, chicken) = map(int, input().split())
	(sbeef, schicken) = map(int, input().split())
	if sbeef > schicken:
		x = schicken
		schicken = sbeef
		sbeef = x
		x = chicken
		chicken = beef
		beef = x
	x = min(buns // 2, chicken)
	buns -= 2 * x
	rs = x * schicken + min(buns // 2, beef) * sbeef
	print(rs)


for w in range(int(input())):
	(b, p, f) = map(int, input().strip().split())
	(h, c) = map(int, input().strip().split())
	v = 0
	if c > h:
		(h, c) = (c, h)
		(p, f) = (f, p)
	z = min(b // 2, p)
	v += h * z
	b -= 2 * z
	if b > 1:
		v += c * min(f, b // 2)
	print(v)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	ans = 0
	while b > 1:
		if f > 0:
			f -= 1
			ans += c
		elif p > 0:
			p -= 1
			ans += h
		b -= 2
	print(ans)


t = int(input())
for i in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	maxb = b // 2
	(h, c) = [int(i) for i in input().split()]
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	hk = min(maxb, p)
	money = h * hk + c * min(maxb - hk, f)
	print(money)


def min(a, b):
	return a if a < b else b
for tt in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	total = 0
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	x = min(p, int(b / 2))
	total = x * h
	if x * 2 < b:
		total += min(f, int(b / 2) - x) * c
	print(total)


t = int(input())
sol = []
while t > 0:
	(b, p, f) = [int(ele) for ele in input().split()]
	(h, c) = [int(ele) for ele in input().split()]
	profit = 0
	if b == 1:
		sol.append(0)
	else:
		b1 = int(b / 2)
		if h >= c:
			if b1 >= p:
				profit += h * p
				b1 -= p
			else:
				profit += h * b1
				b1 = 0
			if b1 > 0:
				if b1 >= f:
					profit += c * f
					b1 -= f
				else:
					profit += c * b1
					b1 = 0
		else:
			if b1 >= f:
				profit += c * f
				b1 -= f
			else:
				profit += c * b1
				b1 = 0
			if b1 > 0:
				if b1 >= p:
					profit += h * p
					b1 -= p
				else:
					profit += h * b1
					b1 = 0
		sol.append(profit)
	t -= 1
for ele in sol:
	print(ele)


t = int(input())
ls = [list(map(int, input().split())) for _ in range(2 * t)]
bpf = []
hc = []
for i in range(2 * t):
	if i % 2 == 0:
		bpf.append(ls[i])
	elif i % 2 == 1:
		hc.append(ls[i])
for j in range(t):
	ans = 0
	if hc[j][0] <= hc[j][1]:
		ans += hc[j][1] * min(bpf[j][0] // 2, bpf[j][2])
		rb = max(0, bpf[j][0] - 2 * bpf[j][2])
		ans += hc[j][0] * min(rb // 2, bpf[j][1])
	elif hc[j][0] > hc[j][1]:
		ans += hc[j][0] * min(bpf[j][0] // 2, bpf[j][1])
		rb = max(0, bpf[j][0] - 2 * bpf[j][1])
		ans += hc[j][1] * min(rb // 2, bpf[j][2])
	print(ans)


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		hs = min(b // 2, p)
		b -= 2 * hs
		cs = min(b // 2, f)
	else:
		cs = min(b // 2, f)
		b -= 2 * cs
		hs = min(b // 2, p)
	print(hs * h + cs * c)


t = int(input())
output = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	if b > 1:
		b //= 2
		if h > c:
			if p > b:
				res += b * h
			else:
				res += p * h
				b = b - p
				if f > b:
					res += b * c
				else:
					res += f * c
		elif f > b:
			res += b * c
		else:
			res += f * c
			b = b - f
			if p > b:
				res += b * h
			else:
				res += p * h
	output.append(str(res))
print('\n'.join(output))


t = int(input())
for case_num in range(t):
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	if h > c:
		tmp = p
		p = f
		f = tmp
		tmp = h
		h = c
		c = tmp
	ans = 0
	nc = min(f, b // 2)
	ans += nc * c
	b -= nc * 2
	nh = min(p, b // 2)
	ans += nh * h
	print(ans)


from math import floor
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if h > c:
		hb = min(floor(b / 2), p)
		b -= 2 * hb
		p -= hb
		profit += h * hb
		cb = min(floor(b / 2), f)
		b -= 2 * cb
		f -= cb
		profit += c * cb
	else:
		cb = min(floor(b / 2), f)
		b -= 2 * cb
		f -= cb
		profit += c * cb
		hb = min(floor(b / 2), p)
		b -= 2 * hb
		p -= hb
		profit += h * hb
	print(profit)


q = int(input())
for i in range(q):
	suma = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if h > c:
		max_cost = h
		min_cost = c
		max_count = p
		min_count = f
	else:
		max_cost = c
		min_cost = h
		max_count = f
		min_count = p
	if b >= max_count:
		b -= max_count
		suma += max_count * max_cost
	else:
		suma += max_cost * b
		b = 0
	if b >= min_count:
		suma += min_cost * min_count
	else:
		suma += min_cost * b
	print(suma)


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a[0] // 2
	if c == 0:
		print(0)
		continue
	if b[0] > b[1]:
		if a[1] >= c:
			print(b[0] * c)
			continue
		else:
			c -= a[1]
			if a[2] >= c:
				print(b[0] * a[1] + b[1] * c)
				continue
			else:
				c -= a[2]
				print(b[0] * a[1] + b[1] * a[2])
				continue
	elif a[2] >= c:
		print(b[1] * c)
		continue
	else:
		c -= a[2]
		if a[1] >= c:
			print(b[1] * a[2] + b[0] * c)
			continue
		else:
			c -= a[1]
			print(b[1] * a[2] + b[0] * a[1])
			continue


import copy

def is_able_create_hamburger(b, p):
	return b >= 2 and p >= 1

def is_able_create_chicken_burger(b, f):
	return b >= 2 and f >= 1
t = int(input())
for i in range(0, t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ingredients = {'b': b, 'p': p, 'f': f}
	hamburger_first_profit = 0
	current_ingredients = copy.deepcopy(ingredients)
	while is_able_create_hamburger(current_ingredients['b'], current_ingredients['p']):
		current_ingredients['b'] -= 2
		current_ingredients['p'] -= 1
		hamburger_first_profit += h
	while is_able_create_chicken_burger(current_ingredients['b'], current_ingredients['f']):
		current_ingredients['b'] -= 2
		current_ingredients['f'] -= 1
		hamburger_first_profit += c
	chicken_burger_first_profit = 0
	current_ingredients = copy.deepcopy(ingredients)
	while is_able_create_chicken_burger(current_ingredients['b'], current_ingredients['f']):
		current_ingredients['b'] -= 2
		current_ingredients['f'] -= 1
		chicken_burger_first_profit += c
	while is_able_create_hamburger(current_ingredients['b'], current_ingredients['p']):
		current_ingredients['b'] -= 2
		current_ingredients['p'] -= 1
		chicken_burger_first_profit += h
	print(max(hamburger_first_profit, chicken_burger_first_profit))


t = int(input())
for i in range(t):
	bpf = list(map(int, input().split()))
	hc = list(map(int, input().split()))
	b = bpf[0]
	p = bpf[1]
	f = bpf[2]
	h = hc[0]
	c = hc[1]
	cost = 0
	if b < 2:
		print(0)
	else:
		if c > h:
			for i in range(0, f):
				if b > 1:
					cost += c
					b -= 2
				else:
					break
			for i in range(0, p):
				if b > 1:
					cost += h
					b -= 2
				else:
					break
		else:
			for i in range(0, p):
				if b > 1:
					cost += h
					b -= 2
				else:
					break
			for i in range(0, f):
				if b > 1:
					cost += c
					b -= 2
				else:
					break
		print(cost)


t = int(input())
for i in range(t):
	ans = 0
	(b, g, k) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		q = min(b // 2, g)
		b -= q * 2
		ans += q * h
		q = min(b // 2, k)
		b -= q * 2
		ans += q * c
	else:
		q = min(b // 2, k)
		b -= q * 2
		ans += q * c
		q = min(b // 2, g)
		b -= q * 2
		ans += q * h
	print(ans)


t = int(input())
x = 0

def count(buns, patty, chicken, pPrice, cPrice):
	total = 0
	if pPrice >= cPrice:
		expensive = pPrice
		expensiveItem = patty
		cheap = cPrice
		cheapItem = chicken
	else:
		expensive = cPrice
		expensiveItem = chicken
		cheap = pPrice
		cheapItem = patty
	while buns > 1 and expensiveItem > 0:
		buns -= 2
		expensiveItem -= 1
		total += expensive
	while buns > 1 and cheapItem > 0:
		buns -= 2
		cheapItem -= 1
		total += cheap
	return total
while x < t:
	(buns, patty, chicken) = map(int, input().split())
	(pPrice, cPrice) = map(int, input().split())
	print(count(buns, patty, chicken, pPrice, cPrice))
	x += 1


import math
t = int(input())
ans = []
for i in range(t):
	burger = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	x = math.floor(b / 2)
	if h > c:
		burger = min(x, p) * h
		burger = burger + (x - min(x, p)) * c
	else:
		burger = min(x, f) * c
		burger = burger + min(p, x - min(x, f)) * h
	ans.append(burger)
for j in range(t):
	print(ans[j])


from math import *
from sys import *
from collections import defaultdict
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def factor(n):
	potentional_p = 3
	itog_list = {}
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			if n in itog_list:
				itog_list[n] += 1
			else:
				itog_list[n] = 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			if potentional_p in itog_list:
				itog_list[potentional_p] += 1
			else:
				itog_list[potentional_p] = 1
		potentional_p += 2
	return itog_list
t = int(stdin.readline())
for _ in range(t):
	(bun, beef, chic) = list(map(int, stdin.readline().split()))
	if bun & 1:
		bun -= 1
	(h, c) = list(map(int, stdin.readline().split()))
	res = 0
	if h >= c:
		if bun >= 2 * beef:
			res += beef * h
			bun -= 2 * beef
		else:
			res += bun // 2 * h
			bun = 0
		if bun != 0:
			if bun >= 2 * chic:
				res += chic * c
				bun -= 2 * chic
			else:
				res += bun // 2 * c
				bun = 0
	else:
		(beef, chic) = (chic, beef)
		(h, c) = (c, h)
		if bun >= 2 * beef:
			res += beef * h
			bun -= 2 * beef
		else:
			res += bun // 2 * h
			bun = 0
		if bun != 0:
			if bun >= 2 * chic:
				res += chic * c
				bun -= 2 * chic
			else:
				res += bun // 2 * c
				bun = 0
	print(res)


import math
import random
import sys
t = int(input())
while t > 0:
	(x, y, z) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		print(min(y, x // 2) * h + min(z, x // 2 - min(y, x // 2)) * c)
	else:
		print(min(z, x // 2) * c + min(y, x // 2 - min(z, x // 2)) * h)
	t -= 1


t = int(input())
a = lambda x, y: min(x, min(x, y))
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	d = {h: p, c: f}
	b //= 2
	mx = max(h, c)
	mn = min(h, c)
	k = a(b, d[mx])
	print(mx * k + mn * a(b - k, d[mn]))


def burger(b, p, f, h, c):
	b = b // 2
	if b >= p + f:
		return p * h + f * c
	elif h > c:
		if b - p >= 0:
			return p * h + (b - p) * c
		else:
			return b * h
	elif c > h:
		if b - f >= 0:
			return f * c + (b - f) * h
		else:
			return b * c
	elif h == c:
		return b * h
	else:
		return 0
n = int(input())
while n > 0:
	l = input().split(' ')
	(b, p, f) = (int(l[0]), int(l[1]), int(l[2]))
	l = input().split(' ')
	(h, c) = (int(l[0]), int(l[1]))
	print(burger(b, p, f, h, c))
	n -= 1


queries = int(input())
for i in range(queries):
	din = 0
	entrada = input().split()
	(b, p, f) = (int(entrada[0]), int(entrada[1]), int(entrada[2]))
	entrada2 = input().split()
	(h, c) = (int(entrada2[0]), int(entrada2[1]))
	if h >= c:
		while b > 1 and p:
			din += h
			b -= 2
			p -= 1
	else:
		while b > 1 and f:
			din += c
			b -= 2
			f -= 1
	if b <= 1:
		print(din)
	elif f == 0:
		while b > 1 and p:
			din += h
			b -= 2
			p -= 1
		print(din)
	elif p == 0:
		while b > 1 and f:
			din += c
			b -= 2
			f -= 1
		print(din)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	b //= 2
	(h, c) = map(int, input().split())
	res = 0
	if c >= h:
		res += min(b, f) * c
		if b <= f:
			print(res)
			continue
		res += min(b - f, p) * h
	else:
		res += min(b, p) * h
		if b <= p:
			print(res)
			continue
		res += min(b - p, f) * c
	print(res)


t = int(input())
ans = []
cnt = 0
for j in range(t):
	s = input()
	a = s.split()
	for i in range(len(a)):
		a[i] = int(a[i])
	s = input()
	b = a[0]
	p = a[1]
	f = a[2]
	aa = s.split()
	for i in range(len(aa)):
		aa[i] = int(aa[i])
	h = aa[0]
	c = aa[1]
	ans.append(0)
	if h > c:
		ans[cnt] += min(b // 2, p) * h + min(max((b - 2 * p) // 2, 0), f) * c
		cnt += 1
	else:
		ans[cnt] += min(b // 2, f) * c + min(max((b - 2 * f) // 2, 0), p) * h
		cnt += 1
for i in range(len(ans)):
	print(ans[i])


n = int(input())
x = []
price = []
for i in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x.append(a)
	price.append(b)
for i in range(n):
	bun = 0
	sum = 0
	if x[i][0] > 1:
		bun = x[i][0] // 2
		if price[i][0] < price[i][1]:
			if bun >= x[i][2]:
				sum += price[i][1] * x[i][2]
				bun -= x[i][2]
				if bun >= x[i][1]:
					sum += price[i][0] * x[i][1]
				else:
					sum += price[i][0] * bun
			else:
				sum += price[i][1] * bun
				bun = 0
		elif bun >= x[i][1]:
			sum += price[i][0] * x[i][1]
			bun -= x[i][1]
			if bun >= x[i][2]:
				sum += price[i][1] * x[i][2]
			else:
				sum += price[i][1] * bun
		else:
			sum += price[i][0] * bun
			bun = 0
		print(sum)
	else:
		print(0)


t = int(input())
inputs = [[]] * t
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	inputs[i] = [b, p, f, h, c]
for (b, p, f, h, c) in inputs:
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	n = b // 2
	ans = min(n, p)
	n -= ans
	ans *= h
	ans += c * min(n, f)
	print(ans)


t = int(input())
for i in range(t):
	res = 0
	checked = 0
	ff = list(map(int, input().split()))
	tt = list(map(int, input().split()))
	if tt[1] >= tt[0]:
		while ff[2] >= 1 and ff[0] >= 2:
			res += tt[1]
			ff[2] -= 1
			ff[0] -= 2
		while ff[0] >= 2 and ff[1] >= 1:
			res += tt[0]
			ff[1] -= 1
			ff[0] -= 2
	else:
		while ff[1] >= 1 and ff[0] >= 2:
			res += tt[0]
			ff[1] -= 1
			ff[0] -= 2
		while ff[0] >= 2 and ff[2] >= 1:
			res += tt[1]
			ff[2] -= 1
			ff[0] -= 2
	print(res)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h > c:
		num = min(b // 2, p)
		b -= num * 2
		num2 = min(b // 2, f)
		print(num * h + num2 * c)
	else:
		num = min(b // 2, f)
		b -= num * 2
		num2 = min(b // 2, p)
		print(num * c + num2 * h)


rd = lambda : [int(x) for x in input().split()]
t = rd()[0]
for i in range(t):
	(b, p, f) = rd()
	(h, c) = rd()
	if h > c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	cur = min(b // 2, f)
	f -= cur
	b -= 2 * cur
	ans = cur * c
	ans += min(b // 2, p) * h
	print(ans)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b < 2:
		print(0)
	else:
		b = b // 2
		beef = min(b, p) * h + min(b - min(b, p), f) * c
		chicken = min(b, f) * c + min(b - min(b, f), p) * h
		print(max(beef, chicken))


n = int(input())
for i in range(n):
	(b, f, n) = map(int, input().split())
	(h, c) = map(int, input().split())
	sum = 0
	if h >= c:
		if b >= 2 * f:
			sum += h * f
			b -= 2 * f
			if b >= 2 * n:
				sum += c * n
			else:
				sum += b // 2 * c
		else:
			sum += b // 2 * h
	elif b >= 2 * n:
		sum += n * c
		b -= 2 * n
		if b >= 2 * f:
			sum += h * f
		else:
			sum += b // 2 * h
	else:
		sum += b // 2 * c
	print(sum)


def purchase(b, pf, amt, c):
	s = min(b // 2, pf)
	amt += s * c
	b -= 2 * s
	pf -= s
	return (b, pf, amt)
for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	amt = 0
	while b > 1 and (p > 0 or f > 0):
		if h >= c:
			if p > 0:
				(b, p, amt) = purchase(b, p, amt, h)
			else:
				(b, f, amt) = purchase(b, f, amt, c)
		elif f > 0:
			(b, f, amt) = purchase(b, f, amt, c)
		else:
			(b, p, amt) = purchase(b, p, amt, h)
	print(amt)


import sys
t = int(input())
while t > 0:
	(b, p, f) = map(int, input().strip(' ').split(' '))
	(h, c) = map(int, input().strip(' ').split(' '))
	max_b = b // 2
	maxi = -1
	if max_b == 0:
		print(0)
	elif p + f <= max_b:
		print(p * h + f * c)
	else:
		for i in range(max_b + 1):
			if i > p or max_b - i > f:
				continue
			res = h * i + c * (max_b - i)
			if res > maxi:
				maxi = res
		print(maxi)
	t -= 1


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
for i in range(t):
	(b, p, f) = listIn()
	(h, c) = listIn()
	m = b // 2
	if c > h:
		m1 = min(f, m)
		cost = m1 * c + min(m - m1, p) * h
	else:
		m1 = min(p, m)
		cost = m1 * h + min(m - m1, f) * c
	print(cost)


t = int(input())
while t:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	nob = b // 2
	tot = 0
	if nob > 0:
		if h >= c:
			if p >= nob:
				tot = nob * h
			else:
				tot = p * h
				if nob - p <= f:
					tot = tot + (nob - p) * c
				else:
					tot = tot + f * c
		elif f >= nob:
			tot = nob * c
		else:
			tot = f * c
			if nob - f <= p:
				tot += (nob - f) * h
			else:
				tot += h * p
	print(tot)
	t -= 1


n = int(input())
for x in range(n):
	k = list(map(int, input().strip().split()[:3]))
	(hbc, cbc) = input().strip().split()[:2]
	hbc = int(hbc)
	cbc = int(cbc)
	bun = int(k[0] / 2)
	ham = k[1]
	chick = k[2]
	if hbc > cbc:
		s = min(bun, ham)
		bun = bun - s
		t = min(bun, chick)
		print(s * hbc + t * cbc)
	else:
		s = min(bun, chick)
		bun = bun - s
		t = min(bun, ham)
		print(s * cbc + t * hbc)


T = int(input())
RES = 0
for i in range(0, T):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	b = b // 2
	P = [p, h]
	F = [f, c]
	mxn = F[0]
	mnn = P[0]
	mxc = F[1]
	mnc = P[1]
	if P[1] > F[1]:
		mxn = P[0]
		mnn = F[0]
		mxc = P[1]
		mnc = F[1]
	if b >= mxn:
		RES = mxn * mxc + min(b - mxn, mnn) * mnc
	else:
		RES = b * mxc
	print(RES)


R = lambda : map(int, input().split())
for i in range(int(input())):
	(b, p, f) = R()
	(h, c) = R()
	if h > c:
		print(h * (min(b, 2 * p) // 2) + c * max(0, min(b - min(b, 2 * p), 2 * f) // 2))
	else:
		print(c * (min(b, 2 * f) // 2) + h * max(0, min(b - min(b, 2 * f), 2 * p) // 2))


def main():
	t = int(input())
	for i in range(t):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		ans1 = min(b // 2, p) * h + min((b - min(b // 2, p) * 2) // 2, f) * c
		ans2 = min(b // 2, f) * c + min((b - min(b // 2, f) * 2) // 2, p) * h
		print(max(ans1, ans2))
main()


p = int(input())
for q in range(p):
	(a, b, c) = map(int, input().split())
	(z, x) = map(int, input().split())
	t = a // 2
	sum = 0
	if max(z, x) == z:
		if t >= b:
			sum += b * z
			t = t - b
			if t >= c:
				sum += c * x
			else:
				sum += t * x
		else:
			sum += t * z
	elif max(z, x) == x:
		if t >= c:
			sum += c * x
			t = t - c
			if t >= b:
				sum += b * z
			else:
				sum += t * z
		else:
			sum += t * x
	print(sum)


R = lambda : map(int, input().split())
(n,) = R()
for _ in [0] * n:
	(b, *a) = R()
	((h, p), (c, f)) = sorted(zip(R(), a))
	m = min(b // 2, f)
	print(m * c + min(p, b // 2 - m) * h)


for _ in range(int(input().strip())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	sands = b // 2
	if f + p <= sands:
		print(p * h + f * c)
	elif h >= c:
		if p <= sands:
			total = h * p
			sands = sands - p
			total += sands * c
		else:
			total = h * sands
		print(total)
	else:
		if f <= sands:
			total = c * f
			sands = sands - f
			total += sands * h
		else:
			total = c * sands
		print(total)


t1 = input()
t = int(t1)
while t > 0:
	result = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if h > c:
		if p <= b:
			result = result + p * h
			b = b - p
			if f <= b:
				result = result + f * c
				print(result)
			else:
				result = result + b * c
				print(result)
		else:
			result = result + b * h
			print(result)
	elif f <= b:
		result = result + f * c
		b = b - f
		if p <= b:
			result = result + p * h
			print(result)
		else:
			result = result + b * h
			print(result)
	else:
		result = result + b * c
		print(result)
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def solution(b, p, f, h, c):
	res1 = 0
	(bb, pp, ff) = (b, p, f)
	while pp > 0 and bb > 1:
		res1 += h
		pp -= 1
		bb -= 2
	while ff > 0 and bb > 1:
		res1 += c
		ff -= 1
		bb -= 2
	res2 = 0
	(bb, pp, ff) = (b, p, f)
	while ff > 0 and bb > 1:
		res2 += c
		ff -= 1
		bb -= 2
	while pp > 0 and bb > 1:
		res2 += h
		pp -= 1
		bb -= 2
	write(max(res1, res2))

def main():
	for _ in range(r_int()):
		(b, p, f) = r_array()
		(h, c) = r_array()
		solution(b, p, f, h, c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


def cal_profit(b, p, f, h, c):
	buns = int(b / 2)
	if buns >= p + f:
		cost = h * p + c * f
		return cost
	if h >= c:
		if buns >= p:
			buns = buns - p
			cost = h * p + buns * c
			return cost
		else:
			cost = buns * h
			return cost
	if c > h:
		if buns >= f:
			buns = buns - f
			cost = c * f + buns * h
			return cost
		else:
			cost = buns * c
			return cost
n = int(input())
i = n
cost = [] * n
while i > 0:
	(buns, patties, cutlets) = input().split()
	(ham, chic) = input().split()
	cost.append(cal_profit(int(buns), int(patties), int(cutlets), int(ham), int(chic)))
	i -= 1
for i in range(n):
	print(cost[i])


t = int(input())
profit = []
for i in range(t):
	k = list(map(int, input().split()))
	l = list(map(int, input().split()))
	pr = 0
	if k[0] % 2 == 1:
		k[0] -= 1
	if l[0] > l[1]:
		n = 0
		n1 = 0
		while k[0] > 0:
			n += 1
			k[0] -= 2
			k[1] -= 1
			if k[1] == 0:
				break
		while k[0] > 0:
			n1 += 1
			k[0] -= 2
			k[2] -= 1
			if k[2] == 0:
				break
		pr = n * l[0] + n1 * l[1]
	elif l[1] > l[0]:
		n = 0
		n1 = 0
		while k[0] > 0:
			n += 1
			k[0] -= 2
			k[2] -= 1
			if k[2] == 0:
				break
		while k[0] > 0:
			n1 += 1
			k[0] -= 2
			k[1] -= 1
			if k[1] == 0:
				break
		pr = n * l[1] + n1 * l[0]
	else:
		n = 0
		while k[0] > 0:
			n += 1
			k[0] -= 2
			k[1] -= 1
			if k[1] == 0:
				break
		while k[0] > 0:
			n += 1
			k[0] -= 2
			k[2] -= 1
			if k[2] == 0:
				break
		pr = n * l[0]
	profit.append(pr)
for y in profit:
	print(y)


t = int(input())
(b, p, f) = (0, 0, 0)
(h, c) = (0, 0)
b2 = 0
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b2 = b // 2
	kq = 0
	if b2 >= p + f:
		kq = p * h + f * c
	elif h >= c:
		if p >= b2:
			kq = b2 * h
		else:
			kq = kq + p * h
			kq = kq + c * min(f, b2 - p)
	elif f >= b2:
		kq = c * b2
	else:
		kq = kq + c * f + h * min(p, b2 - f)
	print(kq)


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	(b, p, f) = gi()
	(h, c) = gi()
	ans = 0
	if h > c:
		tmep = min(b // 2, p)
		ans += tmep * h
		b -= tmep * 2
		ans += min(b // 2, f) * c
	else:
		tmep = min(b // 2, f)
		ans += tmep * c
		b -= tmep * 2
		ans += min(b // 2, p) * h
	print(ans)


import math
t = int(input())
while t is not 0:
	l1 = list(map(int, input().split()))
	b = l1[0]
	p = l1[1]
	f = l1[2]
	l2 = list(map(int, input().split()))
	h = l2[0]
	c = l2[1]
	n = math.floor(b / 2)
	if p + f <= n:
		print(p * h + f * c)
	elif b == 1:
		print(0)
	else:
		sm = 0
		if h > c:
			if n - p > 0:
				sm = h * p + c * (n - p)
			elif n - p == 0:
				sm = sm + h * p
			else:
				sm = sm + n * h
		elif h == c:
			sm = n * h
		elif n - f > 0:
			sm = c * f + h * (n - f)
		elif n - f == 0:
			sm = sm + c * f
		else:
			sm = sm + n * c
		print(sm)
	t = t - 1


a = int(input())
for i in range(a):
	l = list((int(x) for x in input().split()))
	b = l[0]
	p = l[1]
	f = l[2]
	t = list((int(x) for x in input().split()))
	h = t[0]
	c = t[1]
	if h >= c:
		ham = min(b // 2, p)
		chicken = min((b - ham * 2) // 2, f)
		print(ham * h + chicken * c)
	else:
		chicken = min(b // 2, f)
		ham = min((b - chicken * 2) // 2, p)
		print(chicken * c + ham * h)


q = int(input())
for i in range(q):
	(buns, beef, chicken) = [int(x) for x in input().split()]
	(hp, cp) = [int(x) for x in input().split()]
	ans = 0
	burgers = int(buns / 2)
	priciest = max(hp, cp)
	if priciest == hp:
		if beef >= burgers:
			ans = burgers * hp
		else:
			ans += beef * hp
			ans += min(burgers - beef, chicken) * cp
	elif chicken >= burgers:
		ans = burgers * cp
	else:
		ans += chicken * cp
		ans += min(burgers - chicken, beef) * hp
	print(ans)


t = int(input())
an = []
for i in range(t):
	su = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		if b >= f * 2:
			b -= f * 2
			su += c * f
		else:
			kol = b // 2
			b -= kol * 2
			f -= kol
			su += kol * c
		if b >= 2:
			if b >= p * 2:
				b -= p * 2
				su += h * p
			else:
				kol = b // 2
				b -= kol * 2
				p -= kol
				su += kol * h
	else:
		if b >= p * 2:
			b -= p * 2
			su += h * p
		else:
			kol = b // 2
			b -= kol * 2
			p -= kol
			su += kol * h
		if b >= 2:
			if b >= f * 2:
				b -= f * 2
				su += c * f
			else:
				kol = b // 2
				b -= kol * 2
				f -= kol
				su += kol * c
	an.append(su)
for i in range(t):
	print(an[i])


from collections import defaultdict as dc
import sys
import math

def inp():
	p = sys.stdin.readline()
	return p

def ans(h, c, b, p, f):
	x = 0
	l = 2 * p
	q = b - l
	if q > 1:
		x = x + h * p
		z = 2 * f
		r = q - z
		if r >= 0:
			x = x + f * c
		else:
			x = x + q // 2 * c
	else:
		x = x + b // 2 * h
	return x
for _ in range(int(inp())):
	(b, p, f) = list(map(int, inp().split()))
	(h, c) = list(map(int, inp().split()))
	print(max(ans(c, h, b, f, p), ans(h, c, b, p, f)))


for _ in range(int(input())):
	(b, e, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	u = b // 2
	ans = 0
	if x > y:
		if u >= e:
			ans += y * min(u - e, c)
		ans += min(u, e) * x
	else:
		if u >= c:
			ans += x * min(u - c, e)
		ans += min(u, c) * y
	print(ans)


num = int(input())
mas1 = []
mas2 = []
res = []
i = 0
while i < num:
	for a in input().split():
		mas1.append(int(a))
	for b in input().split():
		mas2.append(int(b))
	if mas1[0] <= 1:
		res.append(0)
	else:
		(pr, pr1) = (0, 0)
		if mas2[0] >= mas2[1]:
			number = mas1[0] // 2
			pr = min(mas1[1], number)
			if mas1[0] > 2 * mas1[1]:
				mas1[0] -= 2 * mas1[1]
				number = mas1[0] // 2
				pr1 = min(mas1[2], number)
			x = pr * mas2[0] + pr1 * mas2[1]
			res.append(x)
		else:
			number = mas1[0] // 2
			pr1 = min(mas1[2], number)
			if mas1[0] > 2 * mas1[2]:
				mas1[0] -= 2 * mas1[2]
				number = mas1[0] // 2
				pr = min(mas1[1], number)
			x = pr * mas2[0] + pr1 * mas2[1]
			res.append(x)
	mas1.clear()
	mas2.clear()
	i += 1
for j in res:
	print(j)


import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ANS = 0
	if h >= c:
		x = min(p, b // 2)
		ANS += x * h
		y = min(f, (b - 2 * x) // 2)
		ANS += y * c
	else:
		x = min(f, b // 2)
		ANS += x * c
		y = min(p, (b - 2 * x) // 2)
		ANS += y * h
	print(ANS)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(min(b // 2, p if h > c else f) * max(h, c) + min((b - min(b // 2, p if h > c else f) * 2) // 2, f if h > c else p) * min(h, c))


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if b >= (p + f) * 2:
		print(p * h + f * c)
	elif b < 2:
		print(0)
	else:
		kolko_spravis = b // 2
		viacej = (f, c)
		menej = (p, h)
		if h > c:
			viacej = (p, h)
			menej = (f, c)
		if kolko_spravis <= viacej[0]:
			print(kolko_spravis * viacej[1])
		else:
			print(viacej[0] * viacej[1] + (kolko_spravis - viacej[0]) * menej[1])


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	T = Scanner.int()
	for _ in range(T):
		(b, p, f) = Scanner.map_int()
		(h, c) = Scanner.map_int()
		ans = 0
		if h > c:
			a = min(b // 2, p)
			ans += a * h
			b -= a * 2
			ans += min(b // 2, f) * c
		else:
			a = min(b // 2, f)
			ans += a * c
			b -= a * 2
			ans += min(b // 2, p) * h
		print(ans)
main()


import pdb

def rem(b, p):
	if p * 2 > b:
		return (b // 2, b % 2, p - b // 2)
	return (p, b - p * 2, 0)
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	if h > c:
		(cnt_h, b, p) = rem(b, p)
		(cnt_c, b, f) = rem(b, f)
	else:
		(cnt_c, b, f) = rem(b, f)
		(cnt_h, b, p) = rem(b, p)
	print(cnt_h * h + cnt_c * c)


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h > c:
		(mx1, mx1_cost) = (p, h)
	else:
		(mx1, mx1_cost) = (f, c)
	(mx2, mx2_cost) = (p + f - mx1, h + c - mx1_cost)
	first = min(b // 2, mx1)
	first_pro = first * mx1_cost
	b = b - 2 * first
	b = max(0, b)
	if b:
		second = min(b // 2, mx2)
		first_pro += second * mx2_cost
	print(first_pro)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if max(h, c) == h:
		c1 = min(int(b / 2), p) * h
		if 2 * p > b:
			c2 = 0
		else:
			c2 = min(int(b / 2) - p, f) * c
	else:
		c1 = min(int(b / 2), f) * c
		if 2 * f > b:
			c2 = 0
		else:
			c2 = min(int(b / 2) - f, p) * h
	print(c1 + c2)


for t in range(int(input())):
	(n, b, c) = map(int, input().split())
	(pb, pc) = map(int, input().split())
	s = min(pb, pc)
	l = max(pb, pc)
	cost = 0
	while n > 1:
		if b == 0 and c == 0:
			break
		if l == pc and c > 0:
			cost += pc
			n -= 2
			c -= 1
		elif l == pb and b > 0:
			cost += pb
			n -= 2
			b -= 1
		elif c == 0:
			cost += pb
			n -= 2
			b -= 1
		elif b == 0:
			cost += pc
			n -= 2
			c -= 1
	print(cost)


t = int(input())
while t > 0:
	t -= 1
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	n = b // 2
	max = h if h >= c else c
	profit = 0
	if max == h:
		if p >= n:
			profit += n * h
			n = 0
		else:
			profit += p * h
			n = n - p
		if n != 0:
			if f >= n:
				profit += n * c
				n = 0
			else:
				profit += f * c
				n = n - f
	else:
		if f >= n:
			profit += n * c
			n = 0
		else:
			profit += f * c
			n = n - f
		if n != 0:
			if p >= n:
				profit += n * h
				n = 0
			else:
				profit += p * h
				n = n - p
	print(profit)


def mi():
	return map(int, input().split())
n = int(input())
for _ in range(n):
	(b, p, f) = mi()
	(h, c) = mi()
	b //= 2
	if h > c:
		q = min(b, p)
		ans = min(b, p) * h
		b -= q
		if b:
			ans += min(b, f) * c
	else:
		q = min(b, f)
		ans = min(b, f) * c
		b -= q
		if b:
			ans += min(b, p) * h
	print(ans)


t = int(input())
for w in range(t):
	(b, p, f) = (int(i) for i in input().split())
	(h, c) = (int(i) for i in input().split())
	mp = 0
	if h > c:
		k1 = p
		k2 = f
		k3 = h
		k4 = c
	else:
		k1 = f
		k2 = p
		k3 = c
		k4 = h
	while b > 1 and k1 > 0:
		mp += k3
		b -= 2
		k1 -= 1
	while b > 1 and k2 > 0:
		mp += k4
		b -= 2
		k2 -= 1
	print(mp)


t = int(input())
for i in range(t):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	profit = 0
	if h <= c:
		numchick = min(f, b // 2)
		profit += numchick * c
		b = b - 2 * numchick
		numburg = min(p, b // 2)
		profit += numburg * h
	else:
		numburg = min(p, b // 2)
		profit += numburg * h
		b = b - 2 * numburg
		numchick = min(f, b // 2)
		profit += numchick * c
	print(profit)


num_quries = int(input())
for i in range(num_quries):
	b_p_f = list(map(int, input().split(' ')))
	h_c = list(map(int, input().split(' ')))
	count = 0
	if h_c[1] >= h_c[0]:
		high_p = h_c[1]
		low_p = h_c[0]
		high_m = b_p_f[2]
		low_m = b_p_f[1]
	else:
		high_p = h_c[0]
		low_p = h_c[1]
		high_m = b_p_f[1]
		low_m = b_p_f[2]
	buns = b_p_f[0]
	if buns >= 2 * high_m:
		count += high_p * high_m
		buns -= 2 * high_m
		if buns > 2 * low_m:
			count += low_p * low_m
		else:
			count += low_p * (buns // 2)
			buns = 0
	else:
		count += high_p * (buns // 2)
		buns = 0
	print(count)


n = int(input())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	a = b // 2
	if h >= c:
		if a <= p:
			print(a * h)
		else:
			print(p * h + min(a - p, f) * c)
	elif a <= f:
		print(a * c)
	else:
		print(f * c + min(a - f, p) * h)


def f(buns, beef, chick, b, c):
	if not buns:
		return 0
	nb = 0
	nc = 0
	if b >= c:
		nb = min(buns, beef)
		buns -= nb
		if buns <= 0:
			return nb * b + nc * c
		else:
			nc = min(buns, chick)
	else:
		nc = min(buns, chick)
		buns -= nc
		if buns <= 0:
			return nb * b + nc * c
		else:
			nb = min(buns, beef)
	return nb * b + nc * c
n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	(buns, beef, chick) = (x[0] // 2, x[1], x[2])
	y = list(map(int, input().split()))
	(b, c) = (y[0], y[1])
	print(f(buns, beef, chick, b, c))


n = int(input())
for i in range(0, n):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	b = b // 2
	p1 = max(h, c)
	p2 = min(h, c)
	if p1 == h:
		p11 = p
		p22 = f
	else:
		p11 = f
		p22 = p
	if b - p11 <= 0:
		print(b * p1)
	else:
		x = b - p11
		s = p11 * p1
		if x < p22:
			s = s + x * p2
		else:
			s = s + p22 * p2
		print(s)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(v1, v2) = map(int, input().split())
	ans = 0
	if v1 >= v2:
		bur = a // 2
		ans = min(bur, b) * v1
		bur -= min(bur, b)
		ans += min(bur, c) * v2
	else:
		bur = a // 2
		ans = min(bur, c) * v2
		bur -= min(bur, c)
		ans += min(bur, b) * v1
	print(ans)


for tin in range(int(input())):
	(n, m, k) = map(int, input().split())
	(h, i) = map(int, input().split())
	c = 0
	if h > i:
		if n // 2 >= m:
			n -= m * 2
			c += h * m + min(n // 2 * i, k * i)
		else:
			c = n // 2 * h
	elif n // 2 >= k:
		n -= k * 2
		c += i * k + min(n // 2 * h, m * h)
	else:
		c = n // 2 * i
	print(c)


T = int(input())
for t in range(0, T):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	b1 = int(b // 2)
	cnt1 = 0
	cnt2 = 0
	if b1 <= p:
		cnt1 += b1 * h
	else:
		cnt1 += p * h
		if b1 - p <= f:
			cnt1 += (b1 - p) * c
		else:
			cnt1 += f * c
	if b1 <= f:
		cnt2 += b1 * c
	else:
		cnt2 += f * c
		if b1 - f <= p:
			cnt2 += (b1 - f) * h
		else:
			cnt2 += p * h
	cn = max(cnt1, cnt2)
	print(cn)


n = int(input())
for i in range(n):
	profit = 0
	foods = input().split()
	bun_ctr = int(foods[0])
	beef_ctr = int(foods[1])
	chicken_ctr = int(foods[2])
	prices = input().split()
	ham_price = int(prices[0])
	chicken_price = int(prices[1])
	if chicken_price > ham_price:
		if bun_ctr >= 2 * chicken_ctr:
			profit += chicken_price * chicken_ctr
			bun_ctr -= 2 * chicken_ctr
		else:
			profit += chicken_price * (bun_ctr // 2)
			bun_ctr = 0
		if bun_ctr >= 2 * beef_ctr:
			profit += ham_price * beef_ctr
		else:
			profit += ham_price * (bun_ctr // 2)
	else:
		if bun_ctr >= 2 * beef_ctr:
			profit += ham_price * beef_ctr
			bun_ctr -= 2 * beef_ctr
		else:
			profit += ham_price * (bun_ctr // 2)
			bun_ctr = 0
		if bun_ctr >= 2 * chicken_ctr:
			profit += chicken_price * chicken_ctr
		else:
			profit += chicken_price * (bun_ctr // 2)
	print(profit)


T = int(input())
profitBeef = 0
profitchic = 0
for i in range(T):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b < 2:
		maxprofit = 0
	elif h >= c:
		bp = b // 2
		bc = bp - p
		if bp >= p:
			profitBeef = h * p
		else:
			profitBeef = h * bp
		if bc >= f and bc > 0:
			profitchic = c * f
		elif bc < f and bc > 0:
			profitchic = c * bc
		maxprofit = profitBeef + profitchic
	else:
		bc = b // 2
		bp = bc - f
		if bc >= f:
			profitchic = f * c
		else:
			profitchic = c * bc
		if bp > p and bp > 0:
			profitBeef = h * p
		elif bp < p and bp > 0:
			profitBeef = h * bp
		maxprofit = profitBeef + profitchic
	print(maxprofit)
	maxprofit = 0
	profitBeef = 0
	profitchic = 0


t = int(input(''))
for k in range(0, t):
	(a, e, d) = input('').split(' ')
	(y, z) = input('').split(' ')
	b = int(a)
	p = int(e)
	f = int(d)
	h = int(y)
	c = int(z)
	if c >= h:
		count = 0
		for i in range(0, b):
			if b >= 2 and f > 0:
				b = b - 2
				f = f - 1
				count = count + c
		for g in range(0, b):
			if b >= 2 and p != 0:
				b = b - 2
				p = p - 1
				count = count + h
		print(count)
	else:
		count = 0
		for l in range(0, b):
			if b >= 2 and p > 0:
				b = b - 2
				p = p - 1
				count = count + h
		for w in range(0, b):
			if b >= 2 and f != 0:
				b = b - 2
				f = f - 1
				count = count + c
		print(count)


nq = int(input())
for i in range(nq):
	nums = input().split()
	nums2 = [int(num) for num in nums]
	prices = input().split()
	prices2 = [int(price) for price in prices]
	if prices2[0] > prices2[1]:
		a = 0
		b = 1
	else:
		a = 1
		b = 0
	big = nums2[a + 1]
	smol = nums2[b + 1]
	bigcost = prices2[a]
	smolcost = prices2[b]
	buns = int(nums2[0] / 2)
	if buns < big:
		print(buns * bigcost)
	elif buns < big + smol:
		print(big * bigcost + (buns - big) * smolcost)
	else:
		print(big * bigcost + smol * smolcost)


n = int(input())
m = 0
f = []
while n != 0:
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	b = l[0] // 2
	for i in range(0, b):
		if p[1] > p[0]:
			if l[2] != 0:
				m = m + p[1]
				l[2] -= 1
			elif l[1] != 0:
				m = m + p[0]
				l[1] -= 1
		elif l[1] != 0:
			m = m + p[0]
			l[1] -= 1
		elif l[2] != 0:
			m = m + p[1]
			l[2] -= 1
	f.append(m)
	m = 0
	n -= 1
for i in f:
	print(i)


t = int(input())
while t:
	t -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	ans = 0
	if h > c:
		temp = min(b, p)
		ans += h * temp
		b -= temp
		te1 = min(b, f)
		ans += c * te1
	else:
		temp = min(b, f)
		ans += c * temp
		b -= temp
		te1 = min(b, p)
		ans += h * te1
	print(ans)


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		beef = min(b // 2, p)
		b -= beef * 2
		chicken = min(b // 2, f)
		print(beef * h + chicken * c)
	else:
		chicken = min(b // 2, f)
		b -= chicken * 2
		beef = min(b // 2, p)
		print(beef * h + chicken * c)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	burgers = b // 2
	if h > c:
		if burgers > p:
			hamburgers = p
			chiburgers = min(burgers - p, f)
			price = h * hamburgers + c * chiburgers
		else:
			price = h * burgers
	elif burgers > f:
		chiburgers = f
		hamburgers = min(burgers - f, p)
		price = h * hamburgers + c * chiburgers
	else:
		price = c * burgers
	print(price)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(t,) = I()
while t:
	t -= 1
	(b, p, f) = I()
	b //= 2
	(h, c) = I()
	ans = 0
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	k = min(p, b)
	ans += k * h
	p -= k
	b -= k
	ans += min(f, b) * c
	print(ans)


w = int(input())
while w:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if (p + f) * 2 < b:
		print(f * c + p * h)
	elif h > c:
		if 2 * p < b:
			q = p * h
			b = b - 2 * p
			q = q + b // 2 * c
			print(q)
		else:
			print(b // 2 * h)
	elif 2 * f < b:
		q = f * c
		b = b - 2 * f
		q = q + b // 2 * h
		print(q)
	else:
		print(b // 2 * c)
	w -= 1


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b <= 1:
		print(0)
	elif b > 1:
		b = b // 2
		if c >= h:
			total_ = 0
			min_ = min(b, f)
			total_ += min_ * c
			b -= min_
			min_ = min(b, p)
			total_ += min_ * h
			print(total_)
		elif h > c:
			total_ = 0
			min_ = min(b, p)
			total_ += min_ * h
			b -= min_
			min_ = min(b, f)
			total_ += min_ * c
			print(total_)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b_half = b // 2
	total = 0
	if b_half == 0:
		print(total)
	else:
		if h > c:
			if b_half > p:
				total = p * h + min(b_half - p, f) * c
			else:
				total = b_half * h
		elif b_half > f:
			total = f * c + min(b_half - f, p) * h
		else:
			total = b_half * c
		print(total)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	cash = 0
	pb = b // 2
	myArr = list()
	myArr.append((h, p))
	myArr.append((c, f))
	myArr.sort(reverse=True)
	for pair in myArr:
		mn = min(pb, pair[1])
		cash += mn * pair[0]
		pb -= mn
	print(cash)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(b, p, f) = minput()
	(h, c) = minput()
	profit = 0
	if c > h:
		profit += c * min(b // 2, f)
		b -= min(b // 2, f) * 2
		profit += h * min(b // 2, p)
	else:
		profit += h * min(b // 2, p)
		b -= min(b // 2, p) * 2
		profit += c * min(b // 2, f)
	print(profit)


t = int(input())
while t > 0:
	(b, p, f) = input().split(' ')
	(h, c) = input().split(' ')
	sale = 0
	if int(c) > int(h):
		x = int(b) - 2 * int(f)
		if x <= 1:
			sale += int(b) // 2 * int(c)
		else:
			sale += int(f) * int(c)
			r = x
			x = x - 2 * int(p)
			if x < 0:
				sale += r // 2 * int(h)
			else:
				sale += int(p) * int(h)
	else:
		x = int(b) - 2 * int(p)
		if x <= 1:
			sale += int(b) // 2 * int(h)
		else:
			sale += int(p) * int(h)
			r = x
			x = x - 2 * int(f)
			if x < 0:
				sale += r // 2 * int(c)
			else:
				sale += int(f) * int(c)
	print(sale)
	t -= 1


q = int(input())
for c in range(q):
	(b, p, f) = map(int, input().split())
	(x, y) = map(int, input().split())
	(e1, e2) = (0, 0)
	a = b
	ex = min(b // 2, p)
	b -= 2 * ex
	ey = min(b // 2, f)
	e1 = ex * x + ey * y
	ey = min(a // 2, f)
	a -= 2 * ey
	ex = min(a // 2, p)
	e2 = ex * x + ey * y
	print(max(e1, e2))


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	s = 0
	b = b // 2 * 2
	max_b = b // 2
	if h >= c:
		if p >= max_b:
			s = max_b * h
			max_b = 0
		else:
			max_b -= p
			s += p * h
		if max_b > 0:
			if f >= max_b:
				s += max_b * c
			else:
				s += f * c
	else:
		if f >= max_b:
			s = max_b * c
			max_b = 0
		else:
			max_b -= f
			s += f * c
		if max_b > 0:
			if p >= max_b:
				s += max_b * h
			else:
				s += p * h
	print(s)


t = int(input())
for x in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b == 1:
		print(0)
		continue
	n1 = p
	n2 = f
	b = b // 2
	s = 0
	if h >= c:
		if n1 > b:
			s += b * h
		else:
			s += n1 * h
			r = b - n1
			if n2 > r:
				s += r * c
			else:
				s += n2 * c
	elif n2 > b:
		s += b * c
	else:
		s += n2 * c
		r = b - n2
		if n1 > r:
			s += r * h
		else:
			s += n1 * h
	print(s)


import sys
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	for _ in range(int(input())):
		(b, p, f) = get_ints()
		(h, c) = get_ints()
		t = 0
		b //= 2
		if h > c:
			if b > p:
				t += p * h
				b -= p
				if b > f:
					t += f * c
				else:
					t += b * c
			else:
				t = h * b
		elif b > f:
			t += f * c
			b -= f
			if b > p:
				t += p * h
			else:
				t += b * h
		else:
			t = c * b
		print(t)
main()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = nu()
	for tt in range(t):
		(b, p, f) = num()
		(h, c) = num()
		b //= 2
		if h >= c:
			ss = 0
			xx = min(b, p)
			ss += xx * h
			b -= xx
			xx = min(f, b)
			ss += xx * c
			print(ss)
		else:
			(p, f) = (f, p)
			(h, c) = (c, h)
			ss = 0
			xx = min(b, p)
			ss += xx * h
			b -= xx
			xx = min(f, b)
			ss += xx * c
			print(ss)
solve()


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
t = ii()
for i in range(t):
	(b, p, f) = mi()
	(h, c) = mi()
	rh = rc = 0
	if h > c:
		rh = min(p, b // 2)
		b -= rh * 2
		rc = min(f, b // 2)
	else:
		rc = min(f, b // 2)
		b -= rc * 2
		rh = min(p, b // 2)
	print(rh * h + rc * c)


t = int(input(''))
result = []
for _ in range(t):
	arr = list(map(int, input('').split(' ')))
	arr_2 = list(map(int, input('').split(' ')))
	(b, p, f) = (arr[0], arr[1], arr[2])
	(h, c) = (arr_2[0], arr_2[1])
	if b < 2:
		result.append(0)
		continue
	if b % 2 == 1:
		b = b - 1
	if c > h:
		if p + f <= b // 2:
			result.append(f * c + p * h)
			continue
		elif b // 2 <= f:
			result.append(b * c // 2)
			continue
		else:
			result.append(f * c + (b // 2 - f) * h)
			continue
	elif h > c:
		if p + f <= b // 2:
			result.append(f * c + p * h)
			continue
		elif b // 2 <= p:
			result.append(b * h // 2)
			continue
		else:
			result.append(p * h + (b // 2 - p) * c)
			continue
	else:
		result.append(min(p + f, b // 2) * h)
for i in range(t):
	print(result[i])


test = int(input())
while test > 0:
	test -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		x = min(b // 2, p)
		print(x * h + min((b - x * 2) // 2, f) * c)
	else:
		x = min(b // 2, f)
		print(x * c + min((b - x * 2) // 2, p) * h)


n = int(input())
for i in range(n):
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	cost = 0
	(cb, cc) = input().split()
	(cb, cc) = (int(cb), int(cc))
	if cb > cc:
		x = min(a // 2, b)
		cost = x * cb
		if a - 2 * x > 1:
			t = min((a - 2 * x) // 2, c)
			cost += t * cc
	elif cb < cc:
		x = min(a // 2, c)
		cost = x * cc
		if a - 2 * x > 1:
			t = min((a - 2 * x) // 2, b)
			cost += t * cb
	else:
		x = min(a // 2, c + b)
		cost = x * cb
	print(cost)


n = int(input())
for i in range(n):
	a = [int(a) for a in input().split()]
	b = [int(b) for b in input().split()]
	if a[0] >= 2 * (a[1] + a[2]):
		print(a[1] * b[0] + a[2] * b[1])
	elif max(b[0], b[1]) == b[0]:
		if a[0] <= 2 * a[1]:
			print(a[0] // 2 * b[0])
		else:
			print(a[1] * b[0] + (a[0] - 2 * a[1]) // 2 * b[1])
	elif max(b[0], b[1]) == b[1]:
		if a[0] <= 2 * a[2]:
			print(a[0] // 2 * b[1])
		else:
			print(a[2] * b[1] + (a[0] - 2 * a[2]) // 2 * b[0])


t = int(input())
for i in range(t):
	(b, p, f) = input().split(' ')
	(h, c) = input().split(' ')
	b = int(b)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	profit = 0
	if b <= 1:
		print('0')
		continue
	if h >= c:
		if p <= b // 2:
			profit = p * h
			b = b - p * 2
			if f <= b // 2:
				profit = profit + f * c
			else:
				profit = profit + c * (b // 2)
		else:
			profit = b // 2 * h
	elif f <= b // 2:
		profit = f * c
		b = b - f * 2
		if p <= b // 2:
			profit = profit + p * h
		else:
			profit = profit + h * (b // 2)
	else:
		profit = b // 2 * c
	if profit <= 0:
		print('0')
		break
	print(profit)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	(x1, x2) = map(int, input().split())
	t = a[1] + a[2]
	if a[0] // 2 < 1:
		print(0)
	elif a[0] // 2 >= 1:
		s = 0
		if x1 > x2:
			p = 1
			m = x1
			m1 = x2
		else:
			m = x2
			m1 = x1
			p = 2
		for i in range(min(t, a[0] // 2)):
			if a[p] != 0:
				s += m
				a[p] -= 1
			else:
				s += m1
		print(s)


n = int(input())
for i in range(n):
	stuff = list(map(int, input().split()))
	price = list(map(int, input().split()))
	(c, b) = (stuff[1], stuff[2])
	bun = int(stuff[0] / 2)
	countb = 0
	countc = 0
	if price[1] > price[0]:
		for i in range(stuff[2]):
			if bun > 0:
				countc += 1
				bun -= 1
		for i in range(stuff[1]):
			if bun > 0:
				countb += 1
				bun -= 1
	else:
		for i in range(stuff[1]):
			if bun > 0:
				countb += 1
				bun -= 1
		for i in range(stuff[2]):
			if bun > 0:
				countc += 1
				bun -= 1
	print(countc * price[1] + price[0] * countb)


import math
import sys
import itertools
import itertools

def sa(Type=int):
	return [Type(x) for x in input().split()]

def solve(t):
	(b, p, f) = sa()
	(h, c) = sa()
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	hSold = min(b // 2, p)
	res = h * hSold
	b -= 2 * hSold
	fSold = min(b // 2, f)
	res += c * fSold
	print(res)
t = int(input())
for i in range(t):
	solve(i + 1)


rw = int(input())
for wewq in range(rw):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	t = 0
	if h > c:
		k = min(b, p)
		t += k * h
		b -= k
		k = min(b, f)
		t += k * c
	else:
		k = min(b, f)
		t += k * c
		b -= k
		k = min(b, p)
		t += k * h
	print(t)


def solve():
	t = int(input())
	for i in range(t):
		ans = 0
		(b, p, f) = [int(s) for s in input().split()]
		(h, c) = [int(s) for s in input().split()]
		for x in range(p + 1):
			for y in range(f + 1):
				if 2 * (x + y) <= b:
					price = x * h + y * c
					ans = max(ans, price)
		print(ans)
solve()


ans = []
sol = 0
n = int(input())
for i in range(n):
	(x, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	x = x // 2
	if h > c:
		sol = min(x, p) * h + min(x - min(x, p), f) * c
	else:
		sol = min(x, f) * c + min(x - min(x, f), p) * h
	ans.append(sol)
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	a = input().split()
	s = 0
	(b, p, f) = (int(a[0]), int(a[1]), int(a[2]))
	a = input().split()
	(h, c) = (int(a[0]), int(a[1]))
	if b < 2:
		s = 0
	elif b == 2:
		s = max(h, c)
	elif h > c:
		if b >= 2 * p + 1:
			s += p * h
			b -= 2 * p
			if b >= 2 * f + 1:
				s += f * c
			else:
				s += b // 2 * c
		else:
			s += b // 2 * h
	elif b >= 2 * f + 1:
		s += f * c
		b -= 2 * f
		if b >= 2 * p + 1:
			s += p * h
		else:
			s += b // 2 * h
	else:
		s += b // 2 * c
	print(s)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().strip().split())
	(e, f) = map(int, input().strip().split())
	d = 0
	if a == 1:
		print(0)
		d = 1
	if a % 2 != 0:
		a = a - 1
	a = a // 2
	if e >= f and d != 1:
		if a >= b:
			x = a - b
			if x >= c:
				print(e * b + c * f)
			else:
				print(e * b + x * f)
		else:
			print(a * e)
	if f > e and d != 1:
		if a >= c:
			x = a - c
			if x >= b:
				print(e * b + c * f)
			else:
				print(x * e + c * f)
		else:
			print(a * f)


list1 = []
for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		if b // 2 > f:
			list1.append(f * c + (b // 2 - f) * h if p > b // 2 - f else f * c + p * h)
		else:
			list1.append(b // 2 * c)
	elif b // 2 > p:
		list1.append(p * h + (b // 2 - p) * c if f > b // 2 - p else p * h + f * c)
	else:
		list1.append(b // 2 * h)
for i in list1:
	print(i)


for i in range(int(input())):
	(b, p, c) = map(int, input().split())
	b = b // 2
	(h, k) = map(int, input().split())
	cs = 0
	if h > k:
		cs += h * min(b, p)
		m = min(b, p)
		b -= m
		p -= m
		cs += k * min(b, c)
	else:
		cs += k * min(b, c)
		m = min(b, c)
		b -= m
		c -= m
		cs += h * min(b, p)
	print(cs)


t = int(input())
for i in range(t):
	(b, p, f) = input().split()
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = input().split()
	(h, c) = (int(h), int(c))
	if b < 2:
		profit = 0
	if b // 2 >= p + f:
		profit = p * h + f * c
	elif b // 2 >= p and b // 2 >= f:
		profit = max(c * f + (b // 2 - f) * h, h * p + (b // 2 - p) * c)
	elif b // 2 >= f and b // 2 < p:
		profit = max(c * f + (b // 2 - f) * h, b // 2 * h)
	elif b // 2 >= p and b // 2 < f:
		profit = max(p * h + (b // 2 - p) * c, b // 2 * c)
	else:
		profit = max((b // 2 * c, b // 2 * h))
	print(profit)


case = int(input())
for i in range(case):
	(b, p, f) = (int(v) for v in input().split())
	(h, c) = (int(u) for u in input().split())
	num = b // 2
	if h > c:
		if num > p + f:
			print(p * h + f * c)
		elif num > p:
			print(p * h + (num - p) * c)
		else:
			print(num * h)
	elif num > f + p:
		print(f * c + p * h)
	elif num > f:
		print(f * c + (num - f) * h)
	else:
		print(num * c)


for _ in range(int(input())):
	(b, p, f) = input().split(' ')
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = input().split(' ')
	(h, c) = (int(h), int(c))
	if h > c:
		n_h = min(p, b // 2)
		n_c = min(f, (b - n_h * 2) // 2)
		print(h * n_h + c * n_c)
	else:
		n_c = min(f, b // 2)
		n_h = min(p, (b - n_c * 2) // 2)
		print(h * n_h + c * n_c)


a = int(input())
for i in range(a):
	p = int(0)
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if c[0] > c[1]:
		while b[0] > 1 and b[1] > 0:
			p = p + c[0]
			b[0] = b[0] - 2
			b[1] = b[1] - 1
		while b[0] > 1 and b[2] > 0:
			p = p + c[1]
			b[0] = b[0] - 2
			b[2] = b[2] - 1
	else:
		while b[0] > 1 and b[2] > 0:
			p = p + c[1]
			b[0] = b[0] - 2
			b[2] = b[2] - 1
		while b[0] > 1 and b[1] > 0:
			p = p + c[0]
			b[0] = b[0] - 2
			b[1] = b[1] - 1
	print(p)


t = int(input())
for i in range(t):
	bpf = list(map(int, input().split()))
	hc = list(map(int, input().split()))
	ans = 0
	b = bpf[0]
	if hc[0] > hc[1]:
		if b > bpf[1] * 2:
			b -= bpf[1] * 2
			ans += bpf[1] * hc[0]
		else:
			ans += b // 2 * hc[0]
			b = 0
		ans += min(bpf[2] * 2, b) // 2 * hc[1]
	else:
		if b > bpf[2] * 2:
			b -= bpf[2] * 2
			ans += bpf[2] * hc[1]
		else:
			ans += b // 2 * hc[1]
			b = 0
		ans += min(bpf[1] * 2, b) // 2 * hc[0]
	print(ans)


for _ in range(int(input())):
	(b, pat, f) = map(int, input().split())
	(x, y) = map(int, input().split())
	ans = 0
	if y > x:
		p = b >> 1
		m = min(p, f)
		p -= m
		ans += m * y
		m = min(pat, p)
		ans += m * x
		print(ans)
	else:
		p = b >> 1
		m = min(p, pat)
		p -= m
		ans += m * x
		m = min(f, p)
		ans += m * y
		print(ans)


i = lambda : map(int, input().split())
n = int(input())
for _ in range(n):
	(b, *a) = i()
	((h, p), (c, f)) = sorted(zip(i(), a))
	m = min(b // 2, f)
	print(m * c + min(p, b // 2 - m) * h)


def Spider():
	(b, g, k) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		if g * 2 > b:
			print(int(b / 2) * h)
		else:
			print(g * h + min(int((b - g * 2) / 2), k) * c)
	elif k * 2 > b:
		print(int(b / 2) * c)
	else:
		print(k * c + min(int((b - k * 2) / 2), g) * h)
NUMBER_OF_TIMES = 1
NUMBER_OF_TIMES = int(input())
for NOT_TEMP in range(NUMBER_OF_TIMES):
	Spider()


n = int(input())
for i in range(n):
	f1 = [int(s) for s in input().split(' ')]
	(b, p, f) = (f1[0], f1[1], f1[2])
	f2 = [int(s) for s in input().split(' ')]
	(h, c) = (f2[0], f2[1])
	rez = 0
	b //= 2
	if h < c:
		tmp = h
		h = c
		c = tmp
		tmp = p
		p = f
		f = tmp
	cnt = min(b, p)
	b -= cnt
	p -= cnt
	rez += h * cnt
	cnt = min(b, f)
	b -= cnt
	f -= cnt
	rez += c * cnt
	print(rez)


def calc(n):
	if n > 0:
		return n
	else:
		return 0
t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	avail = b // 2
	if avail > p + f:
		ans = p * h + f * c
	elif h > c:
		ans = min(avail, p) * h + calc(avail - p) * c
	else:
		ans = min(avail, f) * c + calc(avail - f) * h
	print(ans)
	t -= 1


n = int(input())
max_p = []
for i in range(n):
	(b, p, f) = input().split()
	(h, c) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	profit = 0
	if h >= c:
		meat_1 = p
		meat_2 = f
		p_1 = h
		p_2 = c
	else:
		meat_1 = f
		meat_2 = p
		p_1 = c
		p_2 = h
	while b // 2 > 0 and (meat_1 > 0 or meat_2 > 0):
		if meat_1 > 0:
			b -= 2
			meat_1 -= 1
			profit += p_1
		else:
			b -= 2
			meat_2 -= 1
			profit += p_2
	max_p += [profit]
for i in range(n):
	print(max_p[i])


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	hamb = min(b // 2, p + f)
	r = 0
	if h > c:
		while p and hamb:
			r += h
			p -= 1
			hamb -= 1
		while f and hamb:
			r += c
			f -= 1
			hamb -= 1
	else:
		while f and hamb:
			r += c
			f -= 1
			hamb -= 1
		while p and hamb:
			r += h
			p -= 1
			hamb -= 1
	print(r)


t = int(input())
while t > 0:
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	am = 0
	fr = -1
	sc = -1
	fp = -1
	sp = -1
	if h > c:
		fr = p
		sc = f
		fp = h
		sp = c
	else:
		fr = f
		sc = p
		fp = c
		sp = h
	while fr - 1 >= 0 and b - 2 >= 0:
		fr -= 1
		b -= 2
		am += fp
	while sc - 1 >= 0 and b - 2 >= 0:
		sc -= 1
		b -= 2
		am += sp
	print(am)
	t -= 1


t = int(input())
while t:
	t = t - 1
	(b, p, f) = [int(x) for x in input().split(' ')]
	(h, c) = [int(x) for x in input().split(' ')]
	sum = 0
	b = b // 2
	if h > c:
		if b > 0:
			sum = sum + min(b, p) * h
			b = b - p
		if b > 0:
			sum = sum + min(b, f) * c
			b = b - f
	else:
		if b > 0:
			sum = sum + min(b, f) * c
			b = b - f
		if b > 0:
			sum = sum + min(b, p) * h
			b = b - p
	print(sum)


from sys import setcheckinterval, stdin
setcheckinterval(1000)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
for _ in range(iin()):
	(b, p, f) = lin()
	(h, c) = lin()
	(x, y) = (p, f)
	if h < c:
		(x, y) = (y, x)
		(h, c) = (c, h)
	ans = h * min(b // 2, x)
	b -= 2 * x
	if b > 0:
		ans += c * min(b // 2, y)
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	bug = int(b / 2)
	tsum = 0
	if max(h, c) == c:
		g = min(bug, f)
		tsum += g * c
		bug = bug - g
		mm = min(bug, p)
		tsum += mm * h
	else:
		mm = min(bug, p)
		tsum += mm * h
		bug = bug - mm
		g = min(bug, f)
		tsum += g * c
	print(tsum)


for i in range(int(input())):
	ans = 0
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if h > c:
		ans += min(b // 2 * h, p * h)
		b -= p * 2
		ans += min(max(b // 2 * c, 0), f * c)
	else:
		ans += min(b // 2 * c, f * c)
		b -= f * 2
		ans += min(max(b // 2 * h, 0), p * h)
	print(ans)


tc = int(input())
for _ in range(tc):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	b = int(b / 2)
	price = 0
	if h > c:
		while b > 0 and p > 0:
			price = price + h
			p = p - 1
			b = b - 1
		if p == 0 and b > 0:
			while b > 0 and f > 0:
				price = price + c
				f = f - 1
				b = b - 1
	else:
		while b > 0 and f > 0:
			price = price + c
			f = f - 1
			b = b - 1
		if f == 0 and b > 0:
			while b > 0 and p > 0:
				price = price + h
				p = p - 1
				b = b - 1
	print(price)


import math
for _ in range(int(input())):
	s = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c >= h:
		q = b // 2 if b % 2 == 0 else math.floor(b / 2)
		w = min(f, q)
		s += c * w
		b -= w * 2
		q = b // 2 if b % 2 == 0 else math.floor(b / 2)
		s += h * min(p, q)
	else:
		q = b // 2 if b % 2 == 0 else math.floor(b / 2)
		w = min(p, q)
		s += h * w
		b -= w * 2
		q = b // 2 if b % 2 == 0 else math.floor(b / 2)
		s += c * min(f, q)
	print(str(s))


from bisect import *
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()

def fac(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
		ans %= MOD
	return ans
for _ in range(int(input())):
	(b, p, f) = arrIN()
	(h, c) = arrIN()
	if h > c:
		pr = min(b // 2, p) * h
		b = b - 2 * min(b // 2, p)
		pr += min(b // 2, f) * c
	else:
		pr = min(b // 2, f) * c
		b = b - 2 * min(b // 2, f)
		pr += min(b // 2, p) * h
	print(pr)


t = int(input())
for i in range(0, t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	x = 0
	if h >= c:
		a1 = 1
	else:
		a1 = 0
	while (p >= 1 or f >= 1) and b >= 2:
		if a1 == 1:
			if p >= 1:
				p = p - 1
				b = b - 2
				x = x + h
			else:
				a1 = 0
		elif a1 == 0:
			if f >= 1:
				f = f - 1
				b = b - 2
				x = x + c
			else:
				a1 = 1
	print(x)


import sys

def findMax(b, p, f, h, c):
	maxCount = b // 2
	if maxCount == 0:
		return 0
	pf = p + f
	if maxCount <= pf:
		maxCount = maxCount
	else:
		maxCount = pf
	difference = 0
	if h >= c:
		maxWt = h
		maxNo = p
		minWt = c
		minNo = f
	else:
		maxWt = c
		maxNo = f
		minWt = h
		minNo = p
	if maxCount < maxNo:
		difference = maxNo - maxCount
		maxNo -= difference
		minNo -= difference
	maximum1 = 0
	maximum2 = 0
	maximum1 = maxNo * maxWt + (maxCount - maxNo) * minWt
	return maximum1

def main():
	t = int(input())
	while t >= 1:
		(b, p, f) = map(int, input().strip().split())
		(h, c) = map(int, input().strip().split())
		print(findMax(b, p, f, h, c))
		t -= 1
main()


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(b, p, f) = mp()
	(a, k) = mp()
	ans = 0
	if a > k:
		x = min(p, b // 2)
		ans += a * x
		b -= 2 * x
		y = min(b // 2, f)
		ans += k * y
	else:
		x = min(f, b // 2)
		ans += k * x
		b -= 2 * x
		y = min(b // 2, p)
		ans += a * y
	print(ans)


x = lambda : map(int, input().split())
n = int(input())
for __ in range(n):
	(a, b, c) = x()
	(d, e) = x()
	i = 0
	j = 0
	if e > d:
		(b, c) = (c, b)
		(d, e) = (e, d)
	while b > 0 and a > 1:
		a -= 2
		b -= 1
		i += 1
	while a > 1 and c > 0:
		a -= 2
		c -= 1
		j += 1
	print(i * d + j * e)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	for i in range(min(p, b // 2) + 1):
		r = b - 2 * i
		ans = max(ans, i * h + min(r // 2, f) * c)
	print(ans)


t = int(input())
result = []
for idx in range(t):
	(b, p, f) = [int(k) for k in input().split(' ')]
	(h, c) = [int(k) for k in input().split(' ')]
	n = int(b / 2)
	result.append((p * h if n >= p else n * h) + (f * c if n - p >= f else (n - p) * c if n - p > 0 else 0) if h > c else (f * c if n >= f else n * c) + (p * h if n - f >= p else (n - f) * h if n - f > 0 else 0))
for out in result:
	print(out)


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	total = 0
	if b == 1:
		print('0')
		continue
	elif h >= c:
		while p and b > 1:
			total += h
			b -= 2
			p -= 1
		while f and b > 1:
			total += c
			b -= 2
			f -= 1
	else:
		while f and b > 1:
			total += c
			b -= 2
			f -= 1
		while p and b > 1:
			total += h
			b -= 2
			p -= 1
	print(total)


t = int(input())
for i in range(t):
	s = input().split()
	b = int(s[0])
	p = int(s[1])
	f = int(s[2])
	s = input().split()
	h = int(s[0])
	c = int(s[1])
	if b < 2:
		print(0)
	elif b >= 2 * (p + f):
		print(h * p + c * f)
	else:
		pr = 0
		b_new = b
		if h >= c:
			if 2 * p <= b:
				pr += p * h
				b_new -= 2 * p
				print(pr + c * int(b_new / 2))
			else:
				print(int(b / 2) * h)
		elif 2 * f <= b:
			pr += f * c
			b_new -= 2 * f
			print(pr + h * int(b_new / 2))
		else:
			print(int(b / 2) * c)


n = int(input())
profit = []
item = 0
for i in range(n):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if b >= 2 * (p + f):
		profit.append(p * h + f * c)
	elif h >= c:
		if b // 2 >= p:
			profit.append(p * h + (b // 2 - p) * c)
		else:
			profit.append(b // 2 * h)
	elif b // 2 >= f:
		profit.append(f * c + (b // 2 - f) * h)
	else:
		profit.append(b // 2 * c)
print('\n'.join((str(a) for a in profit)))


tt = int(input())
for tc in range(tt):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	ans = 0
	for nb in range(min(b, p) + 1):
		ans = max(ans, nb * h + min(b - nb, f) * c)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(b, p, f) = [int(x) for x in str(input()).split(' ')]
	(h, c) = [int(x) for x in str(input()).split(' ')]
	profit = 0
	if h > c:
		if b >= 2 * p:
			profit += p * h
			b -= 2 * p
			p = 0
		else:
			profit += b // 2 * h
			b = 0
			p -= b // 2
		if b > 0:
			if b >= 2 * f:
				profit += f * c
				b -= 2 * f
				f = 0
			else:
				profit += b // 2 * c
				b = 0
				f -= b // 2
	elif c > h:
		if b >= 2 * f:
			profit += f * c
			b -= 2 * f
			f = 0
		else:
			profit += b // 2 * c
			b = 0
			f -= b // 2
		if b > 0:
			if b >= 2 * p:
				profit += p * h
				b -= 2 * p
				p = 0
			else:
				profit += b // 2 * h
				b = 0
				p -= b // 2
	elif b >= 2 * (p + f):
		profit += h * (p + f)
	else:
		profit += h * (b // 2)
	print(profit)


import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))
t = I()
for _ in range(t):
	ans = 0
	(b, p, f) = LI()
	(h, c) = LI()
	for i in range(p + 1):
		for j in range(f + 1):
			if i * 2 + j * 2 > b:
				continue
			ans = max(ans, h * i + c * j)
	print(ans)


t = int(input())
for _ in range(t):
	(b, p, f) = eval(','.join(input().split()))
	(h, c) = eval(','.join(input().split()))
	b //= 2
	narx = 0
	if h >= c:
		pass
	else:
		(h, c) = (c, h)
		(p, f) = (f, p)
	if 1:
		while b * p != 0:
			narx += h
			b -= 1
			p -= 1
		if b == 0:
			print(narx)
			continue
		while b * f != 0:
			narx += c
			b -= 1
			f -= 1
		print(narx)


t = int(input())
m = 0
while m < t:
	s1 = list(map(int, input().split()))
	b = s1[0]
	p = s1[1]
	f = s1[2]
	s2 = list(map(int, input().split()))
	h = s2[0]
	c = s2[1]
	p1 = 0
	ma = 0
	while p1 <= p:
		f1 = 0
		while f1 <= f:
			if 2 * (p1 + f1) <= b:
				z = p1 * h + f1 * c
				if z > ma:
					ma = z
			f1 = f1 + 1
		p1 = p1 + 1
	print(ma)
	m = m + 1


def gns():
	return list(map(int, input().split()))

def get1(b, p, f):
	pp = min(b // 2, p)
	b -= pp * 2
	ff = min(b // 2, f)
	return (pp, ff)
t = int(input())
for ti in range(t):
	(b, p, f) = gns()
	(h, c) = gns()
	(pp, ff) = get1(b, p, f)
	ans = pp * h + ff * c
	(ff, pp) = get1(b, f, p)
	ans = max(ans, pp * h + ff * c)
	print(ans)


import sys
import math
from collections import defaultdict
from collections import Counter
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	t1 = max(h, c)
	t2 = b // 2
	if t1 == h:
		if t2 <= p:
			print(t2 * h)
		else:
			c1 = p * h
			t2 -= p
			if t2 - f > 0:
				t2 = f
			c1 += t2 * c
			print(c1)
	elif t2 <= f:
		print(t2 * c)
	else:
		c1 = f * c
		t2 -= f
		if t2 - p > 0:
			t2 = p
		c1 += t2 * h
		print(c1)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	answer = 0
	if h > c:
		x = min(b // 2, p)
		answer += x * h
		b -= 2 * x
		if b > 1:
			y = min(b // 2, f)
			answer += c * y
	else:
		x = min(b // 2, f)
		answer += x * c
		b -= 2 * x
		if b > 1:
			y = min(b // 2, p)
			answer += h * y
	print(answer)


import math
t = int(input())
while t:
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	sum = 0
	total = p + f
	ultotal = min(math.floor(b / 2), total)
	sum = 0
	if h <= c:
		while f != 0 and ultotal != 0:
			sum = sum + c
			ultotal = ultotal - 1
			f = f - 1
		while p != 0 and ultotal != 0:
			sum = sum + h
			ultotal = ultotal - 1
			p = p - 1
	else:
		while p != 0 and ultotal != 0:
			sum = sum + h
			ultotal = ultotal - 1
			p = p - 1
		while f != 0 and ultotal != 0:
			sum = sum + c
			ultotal = ultotal - 1
			f = f - 1
	print(sum)
	t = t - 1


n = int(input())
count = 0
d = []
while count < n:
	bb = 0
	cb = 0
	vol = input()
	p = input()
	(bun, beef, chc) = vol.split(' ')
	(bp, cp) = p.split(' ')
	bun = int(bun) // 2
	if int(bp) >= int(cp):
		if bun < int(beef):
			bb += bun
		else:
			bb += int(beef)
			bun -= int(beef)
			if bun < int(chc):
				cb += bun
			else:
				cb += int(chc)
	elif bun <= int(chc):
		cb += bun
	else:
		cb += int(chc)
		bun -= int(chc)
		if bun < int(beef):
			bb += bun
		else:
			bb += int(beef)
	total = bb * int(bp) + cb * int(cp)
	d.append(total)
	count += 1
for x in d:
	print(x)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	burgers = b // 2
	if h > c:
		if burgers >= p:
			ans = p * h + c * min(burgers - p, f)
		else:
			ans = h * burgers
	elif c > h:
		if burgers >= f:
			ans = f * c + h * min(burgers - f, p)
		else:
			ans = c * burgers
	else:
		ans = h * min(burgers, p + f)
	print(ans)


t = int(input())
for i in range(t):
	x = 0
	y = 0
	(b, p, f) = [int(j) for j in input().split()]
	(h, c) = [int(j) for j in input().split()]
	tb = int(b / 2)
	if h > c:
		x = min(tb, p)
		y = min(tb - x, f)
	elif c > h:
		y = min(tb, f)
		x = min(tb - y, p)
	else:
		x = min(tb, p + f)
	print(x * h + y * c)


t = int(input())
for i in range(t):
	f = [int(i) for i in input().split()]
	b = f.pop(0)
	h = [int(i) for i in input().split()]
	if h[0] > h[1]:
		t = 0
	else:
		t = 1
	p = min(b // 2 * h[t], f[t] * h[t])
	b -= 2 * p // h[t]
	if b > 1:
		t += 1
		t %= 2
		p += min(b // 2 * h[t], f[t] * h[t])
	print(p)


n = int(input())
while n:
	n -= 1
	(b, p, f) = input().split(' ')
	b = int(b)
	p = int(p)
	f = int(f)
	(h, c) = input().split(' ')
	h = int(h)
	c = int(c)
	profit = 0
	if h > c:
		while b / 2 >= 1 and p > 0:
			profit += h
			b -= 2
			p -= 1
		while b / 2 >= 1 and f > 0:
			profit += c
			b -= 2
			f -= 1
	else:
		while b / 2 >= 1 and f > 0:
			profit += c
			b -= 2
			f -= 1
		while b / 2 >= 1 and p > 0:
			profit += h
			b -= 2
			p -= 1
	print(profit)


q = int(input())
for _ in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		s = h * min(p, b // 2)
		b = b - 2 * min(p, b // 2)
		s += c * min(b // 2, f)
		print(s)
	else:
		s = c * min(f, b // 2)
		b -= 2 * min(f, b // 2)
		s += h * min(b // 2, p)
		print(s)


def cost(big):
	global b
	while big * 2 > b:
		big -= 1
	b -= 2 * big
	return big
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		ans = cost(f) * c + cost(p) * h
	else:
		ans = cost(p) * h + cost(f) * c
	print(ans)


t = int(input())
for _ in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	b1 = min(b // 2, p) if h > c else min(b // 2, f)
	b2 = b // 2 - b1
	b2 = min(b2, f) if h > c else min(b2, p)
	print(b1 * h + b2 * c if h > c else b1 * c + b2 * h)


t = eval(input())
A = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if 2 * (p + f) <= b:
		n = p * h + f * c
	elif h >= c:
		if b <= 2 * p:
			n = b // 2 * h
		else:
			n = p * h + (b - 2 * p) // 2 * c
	elif b <= 2 * f:
		n = b // 2 * c
	else:
		n = f * c + (b - 2 * f) // 2 * h
	A.append(n)
for j in range(t):
	print(A[j])


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		ans = 0
		if h >= c:
			while b >= 2 and p >= 1:
				ans += h
				b -= 2
				p -= 1
			while b >= 2 and f >= 1:
				ans += c
				b -= 2
				f -= 1
		else:
			while b >= 2 and f >= 1:
				ans += c
				b -= 2
				f -= 1
			while b >= 2 and p >= 1:
				ans += h
				b -= 2
				p -= 1
		print(ans)
main()


queries = int(input())
for _ in range(queries):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	if h > c:
		hamburgers = min(b, p)
		b -= hamburgers
		chicken = min(b, f)
	else:
		chicken = min(b, f)
		b -= chicken
		hamburgers = min(b, p)
	print(h * hamburgers + c * chicken)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	x = b // 2
	ans = 0
	for i in range(x + 1):
		j = x - i
		temp = h * min(p, i) + c * min(f, j)
		ans = max(ans, temp)
	print(ans)


from math import ceil
tc = int(input())
while tc != 0:
	tc -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b == 1:
		print(0)
		continue
	ans = 0
	if h < c:
		x = min(2 * f, b)
		b -= x
		f -= x // 2
		ans += x // 2 * c
		x = min(2 * p, b)
		b -= x
		p -= x // 2
		ans += x // 2 * h
	elif h >= c:
		x = min(2 * p, b)
		b -= x
		p -= x // 2
		ans += x // 2 * h
		x = min(2 * f, b)
		b -= x
		f -= x // 2
		ans += x // 2 * c
	print(ans)


for t in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	dolladolla = 0
	for (x, y) in sorted(zip([p, f], [h, c]), key=lambda x: x[1], reverse=True):
		burgers = min(b // 2, x)
		b -= burgers * 2
		dolladolla += burgers * y
	print(dolladolla)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b_max = b // 2
	if h > c:
		h_max = min(b_max, p)
		rem = max(b_max - h_max, 0)
		c_max = min(rem, f)
	else:
		c_max = min(b_max, f)
		rem = max(b_max - c_max, 0)
		h_max = min(rem, p)
	profit = c_max * c + h_max * h
	print(profit)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	x = max(h, c)
	if b >= 2:
		if x == h:
			y = min(b // 2, p)
			b = b - y * 2
			z = min(b // 2, f)
			print(h * y + c * z)
		else:
			y = min(b // 2, f)
			b = b - y * 2
			z = min(b // 2, p)
			print(h * z + c * y)
	else:
		print(0)


t = int(input())
for z in range(t):
	(a, b, c) = list(map(int, input().split()))
	(q, w) = list(map(int, input().split()))
	if q >= w:
		print(q * min(a // 2, b) + min(max(0, a - 2 * b) // 2, c) * w)
	else:
		print(w * min(a // 2, c) + min(max(0, a - 2 * c) // 2, b) * q)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	cost = 0
	if h >= c:
		while not (b <= 1 or p == 0):
			b -= 2
			p -= 1
			cost += h
		if b > 1:
			while not (b <= 1 or f == 0):
				b -= 2
				f -= 1
				cost += c
	elif h < c:
		while not (b <= 1 or f == 0):
			b -= 2
			f -= 1
			cost += c
		if b > 1:
			while not (b <= 1 or p == 0):
				b -= 2
				p -= 1
				cost += h
	print(cost)


Q = int(input())
Qs = []
for _ in range(Q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	Qs.append([b, p, f, h, c])
for (b, p, f, h, c) in Qs:
	if 2 * (p + f) <= b:
		ans = h * p + f * c
	elif h > c:
		if 2 * p <= b:
			ans = h * p + c * ((b - 2 * p) // 2)
		else:
			ans = h * (b // 2)
	elif 2 * f <= b:
		ans = c * f + h * ((b - 2 * f) // 2)
	else:
		ans = c * (b // 2)
	print(ans)


t = int(input())
u = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b % 2 == 0:
		b = b
	else:
		b = b - 1
	if p * 2 + f * 2 <= b:
		w = p * h + f * c
	elif h <= c:
		if f * 2 <= b:
			q = f * c
			b = b - f * 2
			if p * 2 <= b:
				w = q + p * h
			else:
				w = q + b / 2 * h
		else:
			w = b / 2 * c
	elif p * 2 <= b:
		q = p * h
		b = b - p * 2
		if f * 2 <= b:
			w = q + f * c
		else:
			w = q + b / 2 * c
	else:
		w = b / 2 * h
	u.append(int(w))
for i in range(len(u)):
	print(u[i])


import collections
n = int(input())
while n:
	(x, y, z) = map(int, input().split())
	(u, v) = map(int, input().split())
	ans = 0
	m = x // 2
	if y + z <= m:
		print(y * u + z * v)
	else:
		if u > v:
			if m > y:
				ans += y * u
				m -= y
				if m > z:
					ans += z * v
				else:
					ans += m * v
			else:
				ans += m * u
		elif m > z:
			ans += z * v
			m -= z
			if m > y:
				ans += y * u
			else:
				ans += m * u
		else:
			ans += m * v
		print(ans)
	n -= 1


c = 0
for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b[0] > b[1]:
		print(min(a[0] // 2, a[1]) * b[0] + min(a[0] // 2 - min(a[0] // 2, a[1]), a[2]) * b[1])
	else:
		print(min(a[0] // 2, a[2]) * b[1] + min(a[0] // 2 - min(a[0] // 2, a[2]), a[1]) * b[0])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(b, p, f) = sep()
	(h, c) = sep()
	total = b // 2
	if h > c:
		if p >= total:
			print(total * h)
		elif total - p <= f:
			print(p * h + c * (total - p))
		else:
			print(p * h + c * f)
	elif f >= total:
		print(total * c)
	elif total - f <= p:
		print(f * c + h * (total - f))
	else:
		print(p * h + f * c)
testcase(int(inp()))


import math
import sys

def main():
	(b, h, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	if b <= 1:
		print(0)
		return
	b = b // 2
	if b >= h + c:
		print(h * x + y * c)
	elif y > x:
		print(min(b, c) * y + min(max(0, b - min(b, c)), h) * x)
	else:
		print(min(b, h) * x + min(max(0, b - min(h, b)), c) * y)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


def three_numbers():
	numbers = list(map(int, input().split(sep=' ')))
	m = max(numbers)
	for i in numbers:
		if i != m:
			print(m - i, end=' ')

def gen_and_card_game():
	card = input()
	my_cards = list(input().split(sep=' '))
	for i in my_cards:
		if i[0] == card[0] or i[1] == card[1]:
			print('YES')
			break
	else:
		print('NO')

def kazak_vus_and_contest():
	(a, b, c) = map(int, input().split(sep=' '))
	if a - b <= 0 and a - c <= 0:
		print('YES')
	else:
		print('NO')

def like_A():
	st = input()
	count_a = 0
	for i in st:
		if i == 'a':
			count_a += 1
	if count_a > len(st) - count_a:
		print(len(st))
	else:
		print(count_a + count_a - 1)

def three_piece_candies():
	n = int(input())
	for i in range(n):
		(a, b, c) = map(int, input().split(sep=' '))
		print((a + b + c) // 2)

def re_encryption():
	n = int(input())
	encryption = input()
	decipherment = ''
	k = 0
	while 0 != n:
		k += 1
		n -= k
	for i in range(1, k + 1):
		decipherment += encryption[0]
		encryption = encryption[i:]
	print(decipherment)

def two_type_burgers():
	n = int(input())
	for i in range(n):
		(a, b, c) = map(int, input().split(sep=' '))
		(p_b, p_c) = map(int, input().split(sep=' '))
		sum = 0
		if p_b > p_c:
			if a - b * 2 >= 0:
				a = a - b * 2
				sum += b * p_b
				if a - c * 2 >= 0:
					sum += c * p_c
				else:
					sum += a // 2 * p_c
			else:
				sum += a // 2 * p_b
		elif a - c * 2 >= 0:
			a = a - c * 2
			sum += c * p_c
			if a - b * 2 >= 0:
				sum += b * p_b
			else:
				sum += a // 2 * p_b
		else:
			sum += a // 2 * p_c
		print(sum)
two_type_burgers()


t = int(input())
b = []
p = []
f = []
h = []
c = []
for i in range(t):
	(bt, pt, ft) = input().split(' ')
	b.append(int(bt))
	p.append(int(pt))
	f.append(int(ft))
	(ht, ct) = input().split(' ')
	h.append(int(ht))
	c.append(int(ct))
for i in range(t):
	out = 0
	if h[i] >= c[i]:
		n = min(p[i], int(b[i] / 2))
		out += h[i] * n
		b[i] -= 2 * n
		m = min(f[i], int(b[i] / 2))
		out += c[i] * m
	else:
		n = min(f[i], int(b[i] / 2))
		out += c[i] * n
		b[i] -= 2 * n
		m = min(p[i], int(b[i] / 2))
		out += h[i] * m
	print(out)


for _ in range(int(input())):
	cost = 0
	(b, p, cc) = map(int, input().split())
	b = b // 2
	(h, c) = map(int, input().split())
	if h > c:
		if b >= p:
			cost += h * p
			b -= p
			if b >= cc:
				cost += cc * c
			else:
				cost += c * b
		else:
			cost += h * b
	else:
		(p, cc) = (cc, p)
		(h, c) = (c, h)
		if b >= p:
			cost += h * p
			b -= p
			if b >= cc:
				cost += cc * c
			else:
				cost += c * b
		else:
			cost += h * b
	print(cost)


q = int(input())
for i in range(q):
	(p, c, l) = map(int, input().split())
	(b, s) = map(int, input().split())
	m = max(b, s)
	profit = 0
	while p >= 2 and c and l:
		if m == b:
			profit += b
			c -= 1
			p -= 2
		else:
			profit += s
			l -= 1
			p -= 2
	if p < 2:
		print(profit)
	else:
		while p >= 2:
			if l != 0:
				profit += s
				l -= 1
			elif c != 0:
				profit += b
				c -= 1
			else:
				break
			p -= 2
		print(profit)


t = int(input())
i = int(0)
kol = 0
gg = 0
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		while b >= 2 and f > 0:
			b -= 2
			f -= 1
			kol += c
		while b >= 2 and p > 0:
			b -= 2
			p -= 1
			kol += h
	if h > c:
		while b >= 2 and p > 0:
			b -= 2
			p -= 1
			kol += h
		while b >= 2 and f > 0:
			b -= 2
			f -= 1
			kol += c
	if h == c:
		gg = p + f
		while b >= 2 and gg > 0:
			b -= 2
			gg -= 1
			kol += h
	print(kol)
	kol = 0


t = int(input())
result = str()
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	b //= 2
	(h, c) = list(map(int, input().split()))
	counter = int()
	if h >= c:
		min_c = min(b, p)
		counter += h * min_c
		b -= min_c
		p -= min_c
		min_c = min(b, f)
		counter += c * min_c
		b -= min_c
		f -= min_c
	else:
		min_c = min(b, f)
		counter += c * min_c
		b -= min_c
		f -= min_c
		min_c = min(b, p)
		counter += h * min_c
		b -= min_c
		p -= min_c
	result = f'{result}\n{counter}'.strip()
print(result)


def main():

	class var:
		(b, p, f, h, c) = 5 * [0]
	(var.b, var.p, var.f) = [int(j) for j in input().split()]
	(var.h, var.c) = [int(j) for j in input().split()]

	def f(val):
		count = 0
		if val == 1:
			count = min(int(var.b / 2), var.p)
			var.p -= count
			var.b -= count * 2
		else:
			count = min(int(var.b / 2), var.f)
			var.f -= count
			var.b -= count * 2
		return count
	cost = 0
	if var.h >= var.c:
		cost = f(1) * var.h
	else:
		cost = f(0) * var.c
	cost += f(1) * var.h + f(0) * var.c
	print(int(cost))
for _ in range(int(input())):
	main()


t = int(input())
while t:
	bpf = [int(x) for x in input().split()]
	hc = [int(x) for x in input().split()]
	bpf[0] = bpf[0] // 2
	tot = 0
	t = t - 1
	while bpf[0]:
		bpf[0] = bpf[0] - 1
		if (hc[0] == max(hc) or bpf[2] == 0) and bpf[1] > 0:
			tot = tot + hc[0]
			bpf[1] = bpf[1] - 1
		elif (hc[1] == max(hc) or bpf[1] == 0) and bpf[2] > 0:
			tot = tot + hc[1]
			bpf[2] = bpf[2] - 1
	print(tot)


def sell_h_first(b, p, f, h, c):
	sold = min(b // 2, p)
	profit = sold * h
	b -= 2 * sold
	profit += min(b // 2, f) * c
	return profit

def sell_c_first(b, p, f, h, c):
	sold = min(b // 2, f)
	profit = sold * c
	b -= 2 * sold
	profit += min(b // 2, p) * h
	return profit
t = int(input())
for test_id in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if c > h:
		profit = sell_c_first(b, p, f, h, c)
	elif c < h:
		profit = sell_h_first(b, p, f, h, c)
	elif p > f:
		profit = sell_h_first(b, p, f, h, c)
	else:
		profit = sell_c_first(b, p, f, h, c)
	print(profit)


t = int(input())
for i in range(t):
	(b, p, f) = [int(item) for item in input().split()]
	(h, c) = [int(item) for item in input().split()]
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	b_num = b // 2
	ans = 0
	if p >= b_num:
		ans = h * b_num
	elif p + f >= b_num:
		ans = h * p + c * (b_num - p)
	else:
		ans = h * p + c * f
	print(ans)


q = int(input())
for _ in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if c <= h:
		if p < b // 2:
			ans += h * p
			b -= 2 * p
		else:
			ans += h * (b // 2)
			b = 0
		if f < b // 2:
			ans += c * f
			b -= f
		else:
			ans += c * (b // 2)
			b = 0
	else:
		if f < b // 2:
			ans += c * f
			b -= 2 * f
		else:
			ans += c * (b // 2)
			b = 0
		if p < b // 2:
			ans += h * p
			b -= p
		else:
			ans += h * (b // 2)
			b = 0
	print(ans)


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pr = 0
	if h >= c:
		if 2 * p <= b:
			pr += h * p
			b -= 2 * p
		else:
			pr += b // 2 * h
			b = 1
		if 2 * f <= b:
			pr += c * f
		else:
			pr += b // 2 * c
	if h < c:
		if 2 * f <= b:
			pr += c * f
			b -= 2 * f
		else:
			pr += b // 2 * c
			b = 1
		if 2 * p <= b:
			pr += h * p
		else:
			pr += b // 2 * h
	print(pr)


n = int(input())
for i in range(n):
	price = 0
	(b, p, f) = map(int, input().strip().split())
	(h, c) = map(int, input().strip().split())
	number_of_possible_burgers = b // 2
	if h >= c:
		price += min(number_of_possible_burgers, p) * h
		number_of_possible_burgers -= min(number_of_possible_burgers, p)
		price += min(number_of_possible_burgers, f) * c
	else:
		price += min(number_of_possible_burgers, f) * c
		number_of_possible_burgers -= min(number_of_possible_burgers, f)
		price += min(number_of_possible_burgers, p) * h
	print(price)


integer = int(input())
max_profit = []
for item in range(integer):
	amount_list = []
	price_list = []
	amount = input().split()
	price = input().split()
	for num in amount:
		amount_list.append(int(num))
	for num in price:
		price_list.append(int(num))
	if amount_list[0] >= amount_list[1] * 2 + amount_list[2] * 2:
		max_profit.append(amount_list[1] * price_list[0] + amount_list[2] * price_list[1])
	elif int(price_list[0]) >= int(price_list[1]):
		if int(amount_list[0]) >= int(amount_list[1]) * 2:
			beef_price = int(amount_list[1]) * int(price_list[0])
			amount_list[0] = int(amount_list[0]) - int(amount_list[1]) * 2
			no_of_chicken = amount_list[0] // 2
			chick_price = int(price_list[1]) * no_of_chicken
			max_profit.append(beef_price + chick_price)
		else:
			max_beef = int(amount_list[0]) // 2
			beef_price = max_beef * int(price_list[0])
			amount_list[0] = int(amount_list[0]) - max_beef * 2
			no_of_chicken = amount_list[0] // 2
			chick_price = int(price_list[1]) * no_of_chicken
			max_profit.append(beef_price + chick_price)
	elif int(amount_list[0]) >= int(amount_list[2]) * 2:
		chick_price = int(amount_list[2]) * int(price_list[1])
		amount_list[0] = int(amount_list[0]) - int(amount_list[2]) * 2
		no_of_beef = amount_list[0] // 2
		beef_price = int(price_list[0]) * no_of_beef
		max_profit.append(beef_price + chick_price)
	else:
		max_chick = int(amount_list[0]) // 2
		chick_price = max_chick * int(price_list[1])
		amount_list[0] = int(amount_list[0]) - max_chick * 2
		no_of_beef = amount_list[0] // 2
		beef_price = int(price_list[0]) * no_of_beef
		max_profit.append(beef_price + chick_price)
for items in max_profit:
	print(items)


for i in range(int(input())):
	(a, b, c) = list(map(int, input().split(' ')))
	(d, e) = list(map(int, input().split(' ')))
	x = a // 2
	if d >= e:
		if x >= 1:
			print(d * min(b, x) + e * min(c, x - min(x, b)))
		else:
			print(0)
	elif x >= 1:
		print(min(c, x) * e + d * min(b, x - min(x, c)))
	else:
		print(0)


import math
n = int(input())
while n > 0:
	burger_ing_str = input().split()
	burger_cost_str = input().split()
	(b, p, f) = [int(i) for i in burger_ing_str]
	(h, c) = [int(i) for i in burger_cost_str]
	if (p + f) * 2 <= b:
		answer = p * h + f * c
		print(answer)
	else:
		bul = math.floor(b / 2)
		if h >= c:
			f = bul - p
			if f <= 0:
				answer = bul * h
			else:
				answer = p * h + f * c
			print(answer)
		elif h < c:
			p = bul - f
			if p <= 0:
				answer = bul * c
			else:
				answer = p * h + f * c
			print(answer)
	n -= 1


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		max1 = h
		max2 = p
		min1 = c
	else:
		max1 = c
		max2 = f
		min1 = h
	if p + f <= b / 2:
		ans = p * h + f * c
	elif max2 >= b // 2:
		ans = b // 2 * max1
	else:
		ans = max2 * max1 + min1 * (b // 2 - max2)
	print(ans)


def lis():
	return [int(i) for i in input().split()]

def value():
	return int(input())

def string():
	return input()
for _ in range(value()):
	(a, b, c) = lis()
	(h, ch) = lis()
	tot = 0
	if h > ch:
		if a >= 2 * b:
			tot = h * b
			a -= 2 * b
			if a >= 2 * c:
				tot += ch * c
			else:
				tot += ch * (a // 2)
		else:
			tot = h * (a // 2)
	elif a >= 2 * c:
		tot = ch * c
		a -= 2 * c
		if a >= 2 * b:
			tot += h * b
		else:
			tot += h * (a // 2)
	else:
		tot = ch * (a // 2)
	print(tot)


n = int(input())
M1 = []
M2 = []
for i in range(n):
	L = [int(i) for i in input().split()]
	P = [int(i) for i in input().split()]
	M1.append(L)
	M2.append(P)
for i in range(n):
	L = M1[i]
	P = M2[i]
	if P[0] > P[1]:
		n = L[0] // 2
		if L[1] >= n:
			print(n * P[0])
		elif L[1] + L[2] <= n:
			print(L[1] * P[0] + L[2] * P[1])
		else:
			print(L[1] * P[0] + (n - L[1]) * P[1])
	else:
		n = L[0] // 2
		if L[2] >= n:
			print(n * P[1])
		elif L[1] + L[2] <= n:
			print(L[1] * P[0] + L[2] * P[1])
		else:
			print(L[2] * P[1] + (n - L[2]) * P[0])


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	ans = 0
	if x > y:
		ans = ans + x * min(a // 2, b)
		a = a - 2 * min(a // 2, b)
		ans = ans + y * min(a // 2, c)
	else:
		ans = ans + y * min(a // 2, c)
		a = a - 2 * min(a // 2, c)
		ans = ans + x * min(a // 2, b)
	print(ans)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	bun_p = b // 2
	price = 0
	if h > c:
		if bun_p > p:
			bun_p = bun_p - p
			price += p * h
			if bun_p > f:
				bun_p -= f
				price += f * c
			else:
				f = f - bun_p
				price += bun_p * c
		else:
			p = p - bun_p
			price += h * bun_p
	elif bun_p > f:
		bun_p = bun_p - f
		price += f * c
		if bun_p > p:
			bun_p -= p
			price += p * h
		else:
			p = p - bun_p
			price += bun_p * h
	else:
		f = f - bun_p
		price += c * bun_p
	print(price)


import math
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	q = 0
	if h > c:
		q = min(p, b // 2)
		w = q * h + min((b - q * 2) // 2, f) * c
	else:
		q = min(f, b // 2)
		w = q * c + min((b - q * 2) // 2, p) * h
	print(w)


n = int(input())
for _ in range(n):
	(k, a, b) = map(int, input().split())
	k //= 2
	(x, y) = map(int, input().split())
	_a = [a, x] if x > y else [b, y]
	_b = [a, x] if x <= y else [b, y]
	f = 0
	while _a[0] > 0 and k > 0:
		f += _a[1]
		k -= 1
		_a[0] -= 1
	while _b[0] > 0 and k > 0:
		f += _b[1]
		k -= 1
		_b[0] -= 1
	print(f)


t = int(input())
for q in range(0, t):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if b[0] > b[1]:
		m = min(a[0] // 2, a[1])
		a[0] -= 2 * m
		a[1] -= m
		ans = m * b[0]
		m = min(a[0] // 2, a[2])
		a[0] -= 2 * m
		a[2] -= m
		ans += m * b[1]
		print(ans)
	else:
		m = min(a[0] // 2, a[2])
		a[0] -= 2 * m
		a[2] -= m
		ans = m * b[1]
		m = min(a[0] // 2, a[1])
		a[0] -= 2 * m
		a[1] -= m
		ans += m * b[0]
		print(ans)


def answer():
	n = int(input())
	while n:
		a = [int(x) for x in input().split()]
		(b, p, f) = (a[0], a[1], a[2])
		z = [int(x) for x in input().split()]
		(h, c) = (z[0], z[1])
		if h > c:
			beef_max = min(p, int(b / 2)) * h
			b -= min(p, int(b / 2)) * 2
			chick_set = min(int(b / 2), f) * c
			beef_max += chick_set
			ans = beef_max
		else:
			chick_max = min(f, int(b / 2)) * c
			b -= min(f, int(b / 2)) * 2
			beef_set = min(int(b / 2), p) * h
			chick_max += beef_set
			ans = chick_max
		print(ans)
		n -= 1
answer()


times = int(input())
answer = []
for i in range(times):
	(bread, cow, chicken) = map(int, input().split())
	(price_cow, price_chicken) = map(int, input().split())
	bread //= 2
	acc = 0
	if price_chicken >= price_cow:
		acc += min(bread, chicken) * price_chicken
		if min(bread, chicken) == bread:
			answer.append(acc)
		else:
			bread -= chicken
			acc += min(bread, cow) * price_cow
			answer.append(acc)
	else:
		acc += min(bread, cow) * price_cow
		if min(bread, cow) == bread:
			answer.append(acc)
		else:
			bread -= cow
			acc += min(bread, chicken) * price_chicken
			answer.append(acc)
for elem in answer:
	print(elem)


from fractions import gcd
import math
mod = 1000000007

def inverse(a):
	return pow(a, mod - 2, mod)

def usearch(x, a):
	lft = 0
	rgt = len(a) + 1
	while rgt - lft > 1:
		mid = (rgt + lft) // 2
		if a[mid] <= x:
			lft = mid
		else:
			rgt = mid
	return lft

def solve():
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	for i in range(101):
		for j in range(101):
			if i > p:
				continue
			if j > f:
				continue
			if (i + j) * 2 > b:
				continue
			ans = max([ans, h * i + c * j])
	print(ans)

def main():
	n = int(input())
	for i in range(n):
		solve()
main()


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	money = 0
	if x < y:
		while c > 0 and a > 1:
			c -= 1
			a -= 2
			money += y
		while b > 0 and a > 1:
			b -= 1
			a -= 2
			money += x
	else:
		while b > 0 and a > 1:
			b -= 1
			a -= 2
			money += x
		while c > 0 and a > 1:
			c -= 1
			a -= 2
			money += y
	print(money)


def fun(b, p, f, h, c):
	if b >= p + f:
		return p * h + f * c
	h1 = 0
	h2 = 0
	l1 = 0
	l2 = 0
	profit = 0
	if h > c:
		h1 = h
		h2 = p
		l1 = c
		l2 = f
	else:
		h1 = c
		h2 = f
		l1 = h
		l2 = p
	while b != 0:
		while b != 0 and h2 != 0:
			profit += h1
			h2 -= 1
			b -= 1
		while b != 0 and l2 != 0:
			profit += l1
			l2 -= 1
			b -= 1
	return profit
for _ in range(int(input())):
	(b, p, f) = input().split()
	(h, c) = input().split()
	b = int(int(b) / 2)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	print(fun(b, p, f, h, c))


t = int(input())
for j in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	ans = 0
	n = b // 2
	burg = n
	for i in range(burg):
		if h > c:
			if p > 0:
				n -= 1
				p -= 1
				ans += h
			elif f > 0:
				n -= 1
				f -= 1
				ans += c
			else:
				break
		elif c >= h:
			if f > 0:
				n -= 1
				f -= 1
				ans += c
			elif p > 0:
				n -= 1
				p -= 1
				ans += h
			else:
				break
	print(ans)


import math
t = int(input())
for i in range(t):
	count1 = 0
	count2 = 0
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(y) for y in input().split()]
	if b < 2:
		print(0)
		continue
	if h >= c:
		i = 1
		while b >= 2 and p > 0:
			b = b - 2
			p = p - 1
			i = i + 1
			count1 = count1 + 1
		if b >= 2:
			j = 0
			while b >= 2 and f > 0:
				b = b - 2
				f = f - 1
				j = j + 1
				count2 = count2 + 1
		print(h * count1 + c * count2)
	else:
		i = 1
		while b >= 2 and f > 0:
			b = b - 2
			f = f - 1
			i = i + 1
			count2 = count2 + 1
		if b >= 2:
			j = 0
			while b >= 2 and p > 0:
				b = b - 2
				p = p - 1
				j = j + 1
				count1 = count1 + 1
		print(h * count1 + c * count2)


def int_multiple():
	return [int(c) for c in input().split()]

def int_single():
	return int(input())

def str_multiple():
	return [c for c in input().split()]

def str_single():
	return input()
t = int_single()
res = []
for i in range(t):
	(b, p, f) = int_multiple()
	mxx = int(b / 2)
	(h, c) = int_multiple()
	r = 0
	if h >= c:
		r = min(mxx, p) * h
		mxx -= min(mxx, p)
		r += min(mxx, f) * c
	else:
		r = min(mxx, f) * c
		mxx -= min(mxx, f)
		r += min(mxx, p) * h
	res.append(r)
for w in res:
	print(w)


t = int(input())

def max_profit(b, p, f, h, c):
	profit_1 = 0
	profit_2 = 0
	if h > c:
		temp = min(b, p)
		profit_1 = temp * h
		b = b - temp
		if b > 0:
			temp = min(b, f)
			profit_2 = temp * c
	else:
		temp = min(b, f)
		profit_1 = temp * c
		b = b - temp
		if b > 0:
			temp = min(b, p)
			profit_2 = temp * h
	total_prof = profit_1 + profit_2
	return total_prof
ans = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans.append(max_profit(b // 2, p, f, h, c))
for item in ans:
	print(item)


for t in range(int(input())):
	(bun, beef, chick) = map(int, input().split())
	(pb, pc) = map(int, input().split())
	ans = 0
	if pb >= pc:
		while 1:
			if beef == 0 or bun < 2:
				break
			ans += pb
			beef -= 1
			bun -= 2
		while 1:
			if bun < 2 or chick == 0:
				break
			ans += pc
			bun -= 2
			chick -= 1
	else:
		while 1:
			if bun < 2 or chick == 0:
				break
			ans += pc
			bun -= 2
			chick -= 1
		while 1:
			if beef == 0 or bun < 2:
				break
			ans += pb
			beef -= 1
			bun -= 2
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	cost = 0
	if h > c:
		if b > 2 * p:
			left_bun = b - 2 * p
			cost = h * p + c * (left_bun // 2 if left_bun // 2 < f else f)
		else:
			left_bun = 0
			cost = h * (b // 2)
	elif b > 2 * f:
		left_bun = b - 2 * f
		cost = c * f + h * (left_bun // 2 if left_bun // 2 < p else p)
	else:
		left_bun = 0
		cost = c * (b // 2)
	print(cost)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c >= h:
		if b >= 2 * f:
			pro = f * c
			if b - 2 * f >= 2 * p:
				pro += p * h
			else:
				pro += (b - 2 * f) // 2 * h
		else:
			pro = b // 2 * c
	elif b >= 2 * p:
		pro = p * h
		if b - 2 * p >= 2 * f:
			pro += f * c
		else:
			pro += (b - 2 * p) // 2 * c
	else:
		pro = b // 2 * h
	print(pro)


for w in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	n = b // 2
	if p + f <= n:
		print(p * h + f * c)
	else:
		l = []
		for i in range(p):
			l.append(h)
		for i in range(f):
			l.append(c)
		l.sort(reverse=True)
		q = 0
		for i in range(n):
			q += l[i]
		print(q)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	a //= 2
	ans2 = 0
	if y < x:
		(y, x) = (x, y)
		(c, b) = (b, c)
	if c < a:
		ans1 = y * c
		a -= c
		if b < a:
			ans2 = x * b
		else:
			ans2 = x * a
	else:
		ans1 = y * a
	print(ans1 + ans2)


for i in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	hcount = 0
	ccount = 0
	if h > c:
		for i in range(p):
			if b == 0 or b == 1:
				break
			b = b - 2
			hcount += 1
		if f * 2 <= b:
			ccount = f
		else:
			ccount = b // 2
	else:
		for i in range(f):
			if b == 0 or b == 1:
				break
			b = b - 2
			ccount += 1
		if p * 2 <= b:
			hcount = p
		else:
			hcount = b // 2
	profit = hcount * h + ccount * c
	print(profit)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	l = sorted([(-h, p), (-c, f)])
	for (price, n) in l:
		m = min(b // 2, n)
		b -= 2 * m
		res -= m * price
	print(res)


from math import floor
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = floor(b / 2)
	bcopy = b
	cf = min(b, f) * c
	cf += min(max(bcopy - min(b, f), 0), p) * h
	b = bcopy
	pf = min(b, p) * h
	pf += min(max(bcopy - min(b, p), 0), f) * c
	print(max(cf, pf))


t = int(input())
while t:
	t = t - 1
	(b, p, f) = list(map(int, input().split(' ')))
	(h, c) = list(map(int, input().split(' ')))
	b = b // 2
	if h > c:
		total = h * min(b, p)
		b = b - min(b, p)
		total = total + c * min(b, f)
		print(total)
	else:
		total = c * min(b, f)
		b = b - min(b, f)
		total = total + h * min(b, p)
		print(total)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	c1 = min(b // 2, p)
	c2 = min((b - 2 * c1) // 2, f)
	rls = c1 * h + c2 * c
	print(rls)


def solve(h, c, b, p, f):
	if b < 2:
		return 0
	profit = 0
	if h > c:
		s = b // 2
		if s > p:
			profit += p * h
			s -= p
			profit += min(f, s) * c
			return profit
		else:
			profit += s * h
			return profit
	else:
		s = b // 2
		if s > f:
			profit += f * c
			s -= f
			profit += min(p, s) * h
			return profit
		else:
			profit += s * c
			return profit
test = int(input())
for t in range(test):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(solve(h, c, b, p, f))


def profit(buns, a, b, cost_a, cost_b):
	ans = cost_a * min(buns, a)
	buns -= min(buns, a)
	ans += cost_b * min(buns, b)
	return ans
for _ in range(int(input())):
	(buns, patty, cutlets) = map(int, input().split())
	buns //= 2
	(ham, chic) = map(int, input().split())
	if ham > chic:
		print(profit(buns, patty, cutlets, ham, chic))
	else:
		print(profit(buns, cutlets, patty, chic, ham))


for i in [0] * int(input()):
	total = 0
	(b, p, f) = map(int, input().split())
	b = b // 2
	(h, c) = map(int, input().split())
	if h > c:
		if p > b:
			total += b * h
		else:
			total += p * h
			b -= p
			if f > b:
				total += b * c
			else:
				total += f * c
	elif f > b:
		total += b * c
	else:
		total += f * c
		b -= f
		if p > b:
			total += b * h
		else:
			total += p * h
	print(total)


for i in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	r = 0
	if p <= b // 2:
		r += p * h
		b -= p * 2
		p = 0
	else:
		r += b // 2 * h
		p -= b // 2
		b %= 2
	if f <= b // 2:
		r += f * c
		b -= f * 2
		f = 0
	else:
		r += b // 2 * c
		f -= b // 2
		b %= 2
	print(r)


t = int(input())
out = []
for i in range(t):
	(b, p, f) = list(map(int, input().split(' ')))
	(h, c) = list(map(int, input().split(' ')))
	if c >= h:
		nc = min(f, b // 2)
		nh = min(p, (b - 2 * nc) // 2)
	else:
		nh = min(p, b // 2)
		nc = min(f, (b - 2 * nh) // 2)
	out.append(nh * h + nc * c)
for o in out:
	print(o)


t = int(input())
ans = int
for i in range(t):
	l = list(map(int, input().split()))
	(a, b) = map(int, input().split(' '))
	if l[1] * 2 + l[2] * 2 <= l[0]:
		ans = l[1] * a + l[2] * b
	elif a > b:
		if int(l[0] / 2) > l[1]:
			ans = l[1] * a + (int(l[0] / 2) - l[1]) * b
		else:
			ans = int(l[0] / 2) * a
	elif int(l[0] / 2) > l[2]:
		ans = l[2] * b + (int(l[0] / 2) - l[2]) * a
	else:
		ans = int(l[0] / 2) * b
	print(ans)


t = int(input())
for query in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h > c:
		ans = h * min(b // 2, p)
		b -= min(b // 2, p) * 2
		ans += c * min(b // 2, f)
		print(ans)
	else:
		ans = c * min(b // 2, f)
		b -= min(b // 2, f) * 2
		ans += h * min(b // 2, p)
		print(ans)


t = int(input())
for i in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	buns = b // 2
	tr = (p + f) * 2
	k = p + f
	if b < 2:
		print(0)
	elif tr < b:
		if h == c:
			print(k * h)
		elif h > c:
			a = h * p
			m = (k - p) * c
			print(a + m)
		else:
			a = c * f
			m = (k - f) * h
			print(a + m)
	elif h == c:
		print(buns * h)
	elif c > h:
		bu = buns - f
		if bu < 0:
			a = c * buns
			print(a)
		else:
			a = c * f
			m = bu * h
			print(a + m)
	else:
		bu = buns - p
		if bu < 0:
			a = h * buns
			print(a)
		else:
			a = h * p
			m = bu * c
			print(a + m)


n = int(input())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	p1 = h * min(b // 2, p) + c * min(f, max(0, (b - 2 * p) // 2))
	p2 = c * min(b // 2, f) + h * min(p, max(0, (b - 2 * f) // 2))
	print(max(p1, p2))


for _ in range(int(input())):
	(b, h, c) = map(int, input().split())
	(hp, cp) = map(int, input().split())
	b //= 2
	if hp < cp:
		(hp, cp) = (cp, hp)
		(h, c) = (c, h)
	rp = min(b, h)
	b -= rp
	rf = min(b, c)
	print(hp * rp + cp * rf)


t = int(input())
while t != 0:
	(bun, beef, patty) = map(int, input().split())
	(h, c) = map(int, input().split())
	if bun < 2:
		print(0)
		t -= 1
		continue
	net = 0
	if h > c:
		k = bun // 2
		h_b = min(k, beef)
		net += h_b * h
		bun -= h_b * 2
		o = bun // 2
		c_b = min(o, patty)
		net += c_b * c
		bun -= c_b * 2
	else:
		o = bun // 2
		c_b = min(o, patty)
		net += c_b * c
		bun -= c_b * 2
		k = bun // 2
		h_b = min(k, beef)
		net += h_b * h
		bun -= h_b * 2
	print(net)
	t -= 1


n = int(input())
for i in range(n):
	(buns, beef, chicken) = map(int, input().split(' '))
	(p_beef, p_chicken) = map(int, input().split(' '))
	answer = 0
	if p_beef >= p_chicken:
		max = p_beef
		higher = beef
		min = p_chicken
		lesser = chicken
	else:
		max = p_chicken
		higher = chicken
		min = p_beef
		lesser = beef
	while buns >= 2 and higher:
		buns -= 2
		higher -= 1
		answer += max
	while buns >= 2 and lesser:
		buns -= 2
		lesser -= 1
		answer += min
	print(answer)


t = int(input())
for _ in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	tot = 0
	if h > c:
		can = min(b // 2, p)
		tot = can * h + min(max(0, b // 2 - can), f) * c
	else:
		can = min(b // 2, f)
		tot = can * c + min(max(0, b // 2 - can), p) * h
	print(tot)


import math

def make(b, m, p):
	prof = 0
	b_left = b
	if b >= 2 * m:
		prof = p * m
		b_left = b - 2 * m
	else:
		prof = int(b / 2) * p
		b_left = 0
	return (prof, b_left)

def main():
	t = int(input())
	for i in range(t):
		inp = input().split()
		b = math.floor(int(inp[0]) / 2) * 2
		p = int(inp[1])
		f = int(inp[2])
		inp = input().split()
		h = int(inp[0])
		c = int(inp[1])
		total = 0
		if h > c:
			(total, lb) = make(b, p, h)
			total += make(lb, f, c)[0]
		else:
			(total, lb) = make(b, f, c)
			total += make(lb, p, h)[0]
		print(total)
main()


t = int(input())
an = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		q1 = p
		q2 = f
	else:
		q1 = f
		q2 = p
	x = min(q1, b // 2)
	y = min(q2, b // 2 - x)
	an.append(max(h, c) * x + min(h, c) * y)
for i in an:
	print(i)


def solve():
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	for i in range(p + 1):
		rb = b - 2 * i
		if rb < 0:
			break
		ans = max(ans, h * i + c * min(rb // 2, f))
	return ans

def main():
	q = int(input())
	for _ in range(q):
		print(solve())
main()


t = int(input())
while t > 0:
	t -= 1
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if h > c:
		ch = min(b // 2, p)
		cc = min(b // 2 - ch, f)
	else:
		cc = min(b // 2, f)
		ch = min(b // 2 - cc, p)
	sale = ch * h + cc * c
	print(sale)


n = int(input())
c = []
for i in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = a[0] // 2
	if a[0] < 2:
		c.append(0)
	elif b[0] >= b[1]:
		if z >= a[1]:
			p = a[1]
		else:
			p = z
		if z - p >= 0 and z - p <= a[2]:
			q = z - p
		else:
			q = a[2]
		ans = p * b[0] + q * b[1]
		c.append(ans)
	else:
		if z >= a[2]:
			p = a[2]
		else:
			p = z
		if z - p >= 0 and z - p <= a[1]:
			q = z - p
		else:
			q = a[1]
		ans = p * b[1] + q * b[0]
		c.append(ans)
for j in range(n):
	print(c[j])


for _ in range(int(input())):
	(b, hp, cp) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		m = min(b // 2, hp)
		hp -= m
		b -= 2 * m
		p = m * h
		if b > 0:
			m = min(b // 2, cp)
			p += m * c
	elif c > h:
		m = min(b // 2, cp)
		cp -= m
		b -= 2 * m
		p = m * c
		if b > 0:
			m = min(b // 2, hp)
			p += m * h
	else:
		p = h * min(b // 2, hp + cp)
	print(p)


for i in range(int(input())):
	materials = list(map(int, input().split()))
	much = list(map(int, input().split()))
	MaxPay = 0
	if much[0] > much[1]:
		while materials[0] >= 2 and materials[1] > 0:
			MaxPay += much[0]
			materials[0] -= 2
			materials[1] -= 1
		while materials[0] >= 2 and materials[2] > 0:
			MaxPay += much[1]
			materials[0] -= 2
			materials[2] -= 1
	else:
		while materials[0] >= 2 and materials[2] > 0:
			MaxPay += much[1]
			materials[0] -= 2
			materials[2] -= 1
		while materials[0] >= 2 and materials[1] > 0:
			MaxPay += much[0]
			materials[0] -= 2
			materials[1] -= 1
	print(MaxPay)


testCases = int(input())
for _ in range(testCases):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	profit = 0
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	if h >= c:
		if b >= 2 * p:
			profit += p * h
			b -= 2 * p
			if b >= 2 * f:
				profit += c * f
			else:
				profit += b // 2 * c
		else:
			profit += b // 2 * h
	print(profit)


n = int(input(''))

def profit_cal(b, p, f, h, c):
	if h > c:
		if b >= 2 * p + 2 * f:
			result = p * h + f * c
		elif b < 2 * p:
			result = b // 2 * h
		else:
			result = p * h + (b - 2 * p) // 2 * c
	elif h < c:
		if b >= 2 * p + 2 * f:
			result = p * h + f * c
		elif b < 2 * f:
			result = b // 2 * c
		else:
			result = f * c + (b - 2 * f) // 2 * h
	elif b >= 2 * p + 2 * f:
		result = p * h + f * c
	else:
		result = b // 2 * h
	return result
for i in range(n):
	(b, p, f) = list(map(int, input().strip().split(' ')))
	(h, c) = list(map(int, input().strip().split(' ')))
	print(profit_cal(b, p, f, h, c))


n = int(input())
for i in range(n):
	l = [int(i) for i in input().split()]
	b = l[0]
	p = l[1]
	f = l[2]
	l = [int(i) for i in input().split()]
	h = l[0]
	c = l[1]
	if h > c:
		if b > 2 * p:
			print(h * p + min(int((b - 2 * p) / 2), f) * c)
		else:
			print(int(b / 2) * h)
	elif b > 2 * f:
		print(c * f + min(int((b - 2 * f) / 2), p) * h)
	else:
		print(int(b / 2) * c)


t = int(input())
for i in range(t):
	bpf = list(map(int, input().split(' ')))
	(h, c) = input().split(' ')
	h = int(h)
	c = int(c)
	if c > h:
		(h, c) = (c, h)
		(bpf[1], bpf[2]) = (bpf[2], bpf[1])
	bpf[0] = int(bpf[0] / 2)
	taka = 0
	if bpf[0] >= bpf[1] + bpf[2]:
		taka = bpf[1] * h + bpf[2] * c
	elif bpf[0] >= bpf[1]:
		taka = bpf[1] * h + (bpf[0] - bpf[1]) * c
	else:
		taka = bpf[0] * h
	print(taka)


def solve():
	n = int(input())
	burgers = []
	prices = []
	for i in range(n):
		burgers.append(input())
		prices.append(input())
	for i in range(n):
		(b, p, f) = list(map(lambda x: int(x), burgers[i].split()))
		(h, c) = list(map(lambda x: int(x), prices[i].split()))
		max_burgers = b // 2
		max_price = h if h > c else c
		min_price = c if c <= h else h
		first_burger = p if max_price == h else f
		second_burger = f if first_burger == p else p
		f_cost = max_price * min(max_burgers, first_burger)
		burgers_left = max_burgers - first_burger if max_burgers > first_burger else 0
		print('')
		print(f_cost + min_price * min(burgers_left, second_burger), end=' ')
solve()


t = int(input())
while t is not 0:
	ham = 0
	chic = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		while p * 2 > b:
			p -= 1
		ham = h * p
		b -= p * 2
		while f * 2 > b:
			f -= 1
		chic = f * c
	else:
		while f * 2 > b:
			f -= 1
		chic = f * c
		b -= f * 2
		while p * 2 > b:
			p -= 1
		ham = h * p
	print(ham + chic)
	t -= 1


def find_profit(buns, patty, price):
	if buns > 0:
		if patty * 2 <= buns:
			return [buns - patty * 2, patty * price]
		else:
			return [0, buns // 2 * price]
	return [0, 0]
num = int(input())
for i in range(num):
	ingred = list(map(int, input().split(' ')))
	price = list(map(int, input().split(' ')))
	profit1 = profit2 = 0
	if price[0] > price[1]:
		[ingred[0], profit1] = find_profit(ingred[0], ingred[1], price[0])
		[ingred[0], profit2] = find_profit(ingred[0], ingred[2], price[1])
	else:
		[ingred[0], profit1] = find_profit(ingred[0], ingred[2], price[1])
		[ingred[0], profit2] = find_profit(ingred[0], ingred[1], price[0])
	print(profit1 + profit2)


t = int(input())
while t > 0:
	profit = 0
	t = t - 1
	(buns, beef, chick_cut) = [int(x) for x in input().split()]
	(h, c) = [int(y) for y in input().split()]
	if c > h or c == h:
		while chick_cut > 0 and buns > 1:
			chick_cut = chick_cut - 1
			buns = buns - 2
			profit = profit + c
			if buns < 1:
				break
		while beef > 0 and buns > 1:
			beef = beef - 1
			buns = buns - 2
			profit = profit + h
	elif h > c:
		while beef > 0 and buns > 1:
			beef = beef - 1
			buns = buns - 2
			profit = profit + h
			if buns < 1:
				break
		while chick_cut > 0 and buns > 1:
			if buns < 1:
				break
			chick_cut = chick_cut - 1
			buns = buns - 2
			profit = profit + c
	print(profit)
	profit = 0


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	m = 0
	d = a // 2
	if x >= y:
		z = min(d, b)
		m += z * x
		d -= z
		m += min(c, d) * y
	else:
		z = min(d, c)
		m += z * y
		d -= z
		m += min(b, d) * x
	print(m)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	j = b // 2
	if j == 0:
		print(0)
	elif j >= p + f:
		print(h * p + c * f)
	elif h > c:
		print(min(j, p) * h + max(0, j - p) * c)
	else:
		print(min(j, f) * c + max(0, j - f) * h)


t = int(input())
incomes = []
for _ in range(t):
	(b, p, f) = input().split(' ')
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = input().split(' ')
	(h, c) = (int(h), int(c))
	income = 0
	burgers = b // 2
	if c >= h:
		val = min(f, burgers)
		income += c * val
		burgers -= val
		val = min(p, burgers)
		income += h * val
	else:
		val = min(p, burgers)
		income += h * val
		burgers -= val
		val = min(f, burgers)
		income += c * val
	incomes.append(income)
for i in incomes:
	print(int(i))


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	ham = min(p, b // 2)
	ans = ham * h
	b -= 2 * ham
	chicken = min(f, b // 2)
	ans += chicken * c
	print(ans)


t = int(input())
bpf = []
hc = []
for i in range(2 * t):
	if i % 2 == 0:
		inp = input().split()
		(inp[0], inp[1], inp[2]) = (int(int(inp[0]) // 2), int(inp[1]), int(inp[2]))
		bpf.append(inp)
	else:
		inp = input().split()
		(inp[0], inp[1]) = (int(inp[0]), int(inp[1]))
		hc.append(inp)
summer = []
for i in range(t):
	if bpf[i][0] == 0:
		summer.append(0)
	else:
		Ans = 0
		maximum_hc = max(hc[i][0], hc[i][1])
		for i1 in range(2):
			if hc[i][i1] == maximum_hc:
				a = i1
		if a == 1:
			b = 0
		elif a == 0:
			b = 1
		a1 = a + 1
		b1 = b + 1
		if bpf[i][a1] > bpf[i][0]:
			Ans = hc[i][a] * bpf[i][0]
		else:
			bpf[i][0] -= bpf[i][a1]
			Ans += bpf[i][a1] * hc[i][a]
			if bpf[i][b1] >= bpf[i][0]:
				Ans += bpf[i][0] * hc[i][b]
			else:
				Ans += bpf[i][b1] * hc[i][b]
		summer.append(Ans)
for i in range(len(summer)):
	print(summer[i])


n = int(input())
for _ in range(n):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	nb = l1[0] // 2
	if nb > l1[1] + l1[2]:
		p = l1[1] * l2[0] + l1[2] * l2[1]
		print(p)
	elif l2[0] > l2[1]:
		p = min(l1[1], nb) * l2[0]
		n2 = nb - min(l1[1], nb)
		if n2 > 0:
			p += n2 * l2[1]
		print(p)
	else:
		p = min(l1[2], nb) * l2[1]
		n2 = nb - min(l1[2], nb)
		if n2 > 0:
			p += n2 * l2[0]
		print(p)


n = int(input())
while n > 0:
	(b, p, f) = map(int, input().split())
	b = b // 2
	(h, c) = map(int, input().split())
	ans = int(0)
	if c > h:
		ans = min(f, b) * c
		b = b - min(f, b)
	else:
		ans = min(p, b) * h
		b = b - min(p, b)
	if c <= h:
		ans = ans + min(f, b) * c
	else:
		ans = ans + min(p, b) * h
	print(ans)
	n = n - 1


def check(b, p):
	if b >= 2 and p >= 1:
		b = b - 2
		p = p - 1
		return 1 + check(b, p)
	else:
		return 0
t = int(input())
numOfChe = 0
numofHum = 0
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		numOfChe = check(b, f)
		b = b - numOfChe * 2
		numofHum = check(b, p)
		print(numOfChe * c + numofHum * h)
	else:
		numOfChe = check(b, p)
		b = b - numOfChe * 2
		numofHum = check(b, f)
		print(numOfChe * h + numofHum * c)


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for i in range(t):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		ans = 0
		if h < c:
			(h, c) = (c, h)
			(p, f) = (f, p)
		while b >= 2:
			if p:
				p -= 1
				ans += h
			elif f:
				f -= 1
				ans += c
			else:
				break
			b -= 2
		print(ans)
	return 0
main()


for _ in range(int(input())):
	(b, bp, cp) = map(int, input().split())
	s = 0
	(h, c) = map(int, input().split())
	if h > c:
		v = min(b // 2, bp)
		s = v * h
		b = b - v * 2
		s = s + min(b // 2, cp) * c
	else:
		v = min(b // 2, cp)
		s = v * c
		b = b - v * 2
		s = s + min(b // 2, bp) * h
	print(s)


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	(ham, chi) = (0, 0)
	if h > c:
		ham = min(b, p)
		b -= ham
		chi = min(b, f)
		print(ham * h + chi * c)
	else:
		chi = min(b, f)
		b -= chi
		ham = min(b, p)
		print(ham * h + chi * c)


t = int(input())
for i in range(t):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	b = A[0] // 2
	if B[0] >= B[1]:
		if b > A[1]:
			if b - A[1] > A[2]:
				P = A[1] * B[0] + A[2] * B[1]
			else:
				P = A[1] * B[0] + (b - A[1]) * B[1]
		else:
			P = b * B[0]
	elif b > A[2]:
		if b - A[2] > A[1]:
			P = A[1] * B[0] + A[2] * B[1]
		else:
			P = (b - A[2]) * B[0] + A[2] * B[1]
	else:
		P = b * B[1]
	print(P)


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import math
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		hh = min(b // 2, p)
		pp = hh * h
		cc = min((b - hh * 2) // 2, f)
		pp += cc * c
	else:
		cc = min(b // 2, f)
		pp = cc * c
		hh = min((b - cc * 2) // 2, p)
		pp += hh * h
	print(pp)


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	ans = 0
	for beef in range(p + 1):
		buns = b - 2 * beef
		chick = min(buns // 2, f)
		if buns < 0:
			continue
		ans = max(ans, beef * h + c * chick)
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	amt = 0
	burgersAvailable = b // 2
	if burgersAvailable:
		if h > c:
			hamburgers = min(p, burgersAvailable)
			amt += hamburgers * h
			burgersAvailable -= hamburgers
			chicken = min(f, burgersAvailable)
			amt += chicken * c
			print(amt)
		else:
			chicken = min(f, burgersAvailable)
			amt += chicken * c
			burgersAvailable -= chicken
			hamburgers = min(p, burgersAvailable)
			amt += hamburgers * h
			print(amt)
	else:
		print(amt)


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		ans = -1
		for np in range(p + 1):
			h_num = min(np, b // 2)
			c_num = min(f, (b - h_num * 2) // 2)
			ans = max(ans, h * h_num + c * c_num)
		print(ans)
main()


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b < 2:
		print('0')
	elif (p + f) * 2 < b:
		print(p * h + f * c)
	elif max(h, c) == c:
		if 2 * f < b:
			print(f * c + (b - 2 * f) // 2 * h)
		else:
			print(b // 2 * c)
	elif 2 * p < b:
		print(p * h + (b - 2 * p) // 2 * c)
	else:
		print(b // 2 * h)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	nob = b // 2
	nom = p + f
	n = min(nom, nob)
	if n == 0:
		res = 0
	elif nom == n:
		res = h * p + c * f
	elif h >= c:
		if n > p:
			res = h * p + (n - p) * c
		elif n < p:
			res = n * h
		else:
			res = p * h
	elif n > f:
		res = f * c + (n - f) * h
	elif n < f:
		res = n * c
	else:
		res = f * c
	print(res)


def testCase():
	(bun, p, f) = tuple(map(int, input().split()))
	(h, c) = tuple(map(int, input().split()))
	count = bun // 2
	if h < c:
		(f, p) = (p, f)
		(c, h) = (h, c)
	n1 = min(count, p)
	n2 = min(count - n1, f)
	return n1 * h + n2 * c
t = int(input())
ans = [str(testCase()) for x in range(t)]
print('\n'.join(ans))


t = int(input())
while t:
	l = list(map(int, input().split()))
	li = list(map(int, input().split()))
	(b, p, f) = (l[0], l[1], l[2])
	(h, c) = (li[0], li[1])
	s = 0
	if h > c:
		while b > 1 and p > 0:
			s = s + h
			b = b - 2
			p = p - 1
		while b > 1 and f > 0:
			s = s + c
			b = b - 2
			f = f - 1
	else:
		while b > 1 and f > 0:
			s = s + c
			b = b - 2
			f = f - 1
		while b > 1 and p > 0:
			s = s + h
			b = b - 2
			p = p - 1
	print(s)
	t = t - 1


profit = []
t = input()
for i in range(int(t)):
	pet = input()
	pet = pet.split(' ')
	b = int(pet[0])
	p = int(pet[1])
	f = int(pet[2])
	cost = input()
	cost = cost.split(' ')
	h = int(cost[0])
	c = int(cost[1])
	burgers_to_be_done = int(b / 2)
	if burgers_to_be_done > 0:
		if burgers_to_be_done < p + f:
			if h >= c:
				if burgers_to_be_done < p:
					tc = burgers_to_be_done * h
				else:
					tc = p * h
					burgers_to_be_done -= p
					tc += burgers_to_be_done * c
			elif burgers_to_be_done < f:
				tc = burgers_to_be_done * c
			else:
				tc = f * c
				burgers_to_be_done -= f
				tc += burgers_to_be_done * h
		else:
			tc = p * h + f * c
		profit.append(tc)
	else:
		profit.append(burgers_to_be_done)
for x in profit:
	print(x)


MainLoop = int(input())
for i in range(MainLoop):
	answ = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a[0] //= 2
	bigP = 0
	lowP = 0
	bigF = 0
	lowF = 0
	if b[0] > b[1]:
		bigP = 1
		lowP = 2
		bigF = 0
		lowF = 1
	else:
		bigP = 2
		lowP = 1
		bigF = 1
		lowF = 0
	if a[bigP] > a[0]:
		answ = a[0] * b[bigF]
	else:
		answ = a[bigP] * b[bigF]
		a[0] -= a[bigP]
		if a[lowP] > a[0]:
			answ += a[0] * b[lowF]
		else:
			answ += a[lowP] * b[lowF]
	print(answ)


T = int(input())
for _ in range(T):
	(B, P, F) = map(int, input().split())
	(H, C) = map(int, input().split())
	MaxA = min(B // 2, P + F)
	if H > C:
		MaxH = min(B // 2, P)
		res = MaxH * H + min(max(MaxA - MaxH, 0), F) * C
	else:
		MaxC = min(B // 2, F)
		res = MaxC * C + min(max(MaxA - MaxC, 0), P) * H
	print(res)


n = int(input())
j = 0
k = 0
for i in range(0, n):
	income = 0
	(b, p, f) = input().split()
	(h, c) = input().split()
	ib = int(b)
	ih = int(h)
	ic = int(c)
	if int(c) >= int(h) and ib > 1:
		for i in range(1, int(f) + 1):
			if ib > 1:
				j += 1
				ib -= 2
		income = j * ic
		j = 0
		for i in range(1, int(p) + 1):
			if ib > 1:
				k += 1
				ib -= 2
		income = income + k * ih
		k = 0
	elif ic < ih and ib > 1:
		for i in range(1, int(p) + 1):
			if ib > 1:
				j += 1
				ib -= 2
		income = j * ih
		j = 0
		for i in range(1, int(f) + 1):
			if ib > 1:
				k += 1
				ib -= 2
		income = income + k * ic
		k = 0
	print(income)


def solve(b, mx, mn, mxp, mnp):
	ans = 0
	while mx > 0 and b > 1:
		b -= 2
		mx -= 1
		ans += mxp
	while mn > 0 and b > 1:
		b -= 2
		mn -= 1
		ans += mnp
	return ans
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		ans = solve(b, p, f, h, c)
	else:
		ans = solve(b, f, p, c, h)
	print(ans)


p = int(input())
for i in range(p):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	if c > h:
		(p, f) = (f, p)
		(h, c) = (c, h)
	ans1 = min(b, p) * h
	ans2 = min(max(b - p, 0), f) * c
	print(ans1 + ans2)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	temp = 0
	gg = 0
	if h > c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	for i in range(1, f + 1):
		if b >= 2 * i and b > 1:
			ans = i * c
			temp = i
	b -= 2 * temp
	for j in range(1, p + 1):
		if b <= 1:
			break
		if b >= 2 * j and b > 1:
			gg = j * h
	ans += gg
	print(ans)


import math
n = int(input())
ans = 0
for i in range(n):
	a = [int(e) for e in input().split()]
	b = [int(e) for e in input().split()]
	if b[0] >= b[1]:
		ans += min(a[0] // 2, a[1]) * b[0]
		a[0] -= min(a[0] // 2, a[1]) * 2
		ans += min(a[0] // 2, a[2]) * b[1]
	else:
		ans += min(a[0] // 2, a[2]) * b[1]
		a[0] -= min(a[0] // 2, a[2]) * 2
		ans += min(a[0] // 2, a[1]) * b[0]
	print(ans)
	ans = 0


q = int(input())
for i in range(q):
	a = input()
	(b, p, f) = [int(k) for k in a.split()]
	s = input()
	(h, c) = [int(k) for k in s.split()]
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	print(min(b // 2, p) * h + min(max(0, (b - 2 * p) // 2), f) * c)


for i in range(int(input())):
	(buns, beef, chicken) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if buns // 2 < 1:
		print(0)
	elif beef + chicken <= buns // 2:
		print(h * beef + c * chicken)
	else:
		count = buns // 2
		if max(h, c) == c:
			print(c * min(chicken, count) + h * max(0, count - chicken))
		else:
			print(h * min(beef, count) + c * max(0, count - beef))


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	b //= 2
	d = min(b, p)
	a = d * h
	b -= d
	a += min(b, f) * c
	print(a)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	mx = 0
	if h >= c:
		while b > 1 and p:
			b -= 2
			p -= 1
			mx += h
		while b > 1 and f:
			b -= 2
			f -= 1
			mx += c
	else:
		while b > 1 and f:
			b -= 2
			f -= 1
			mx += c
		while b > 1 and p:
			b -= 2
			p -= 1
			mx += h
	print(mx)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	k = b // 2
	max1 = min(b // 2, p) * h + min(k - min(b // 2, p), f) * c
	max2 = min(b // 2, f) * c + min(k - min(b // 2, f), p) * h
	print(max(max1, max2))


t = int(input())
for _ in range(t):
	(bun, beef, chick) = map(int, input().split())
	(ham_burger, chick_burger) = map(int, input().split())
	if bun < 2:
		print(0)
	elif 2 * (beef + chick) <= bun:
		print(ham_burger * beef + chick_burger * chick)
	else:
		if ham_burger > chick_burger:
			if 2 * beef <= bun:
				result = beef * ham_burger
				bun = bun - 2 * beef
				if bun > 1:
					if chick * 2 <= bun:
						result = result + chick * chick_burger
					else:
						result = result + int(bun / 2) * chick_burger
			else:
				result = int(bun / 2) * ham_burger
		elif 2 * chick <= bun:
			result = chick * chick_burger
			bun = bun - 2 * chick
			if bun > 1:
				if beef * 2 <= bun:
					result = result + beef * ham_burger
				else:
					result = result + int(bun / 2) * ham_burger
		else:
			result = int(bun / 2) * chick_burger
		print(result)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	profit = 0
	if h > c:
		mx = h
		mn = c
		m1 = p
		m2 = f
	else:
		mx = c
		mn = h
		m1 = f
		m2 = p
	m1 = min(b, m1)
	profit += m1 * mx
	b -= m1
	m2 = min(b, m2)
	profit += mn * m2
	print(profit)


for _ in range(int(input())):
	(b, h, c) = map(int, input().split())
	(h1, c1) = map(int, input().split())
	if b == 1:
		print('0')
	elif b >= c * 2 + h * 2:
		print(c * c1 + h * h1)
	elif c1 > h1:
		if b >= c * 2:
			b = b - c * 2
			if b <= h * 2:
				b = b // 2
				print(b * h1 + c * c1)
		else:
			print(b // 2 * c1)
	elif h1 >= c1:
		if b >= h * 2:
			b = b - h * 2
			if b <= c * 2:
				b = b // 2
				print(b * c1 + h * h1)
		else:
			print(b // 2 * h1)


t = int(input())
for i in range(t):
	(b, p, ch) = [int(i) for i in input().split(' ')]
	(c, h) = [int(i) for i in input().split(' ')]
	tot = 0
	a = int(b / 2)
	if a == 0:
		print(0)
	else:
		s = p + ch
		if s <= a:
			print(ch * h + c * p)
		elif h >= c:
			if a - ch == 0:
				print(ch * h)
			elif a - ch < 0:
				print(a * h)
			elif a - ch > 0:
				a = a - ch
				tot += ch * h
				if a - p >= 0:
					print(tot + c * p)
				elif a - p < 0:
					print(tot + a * c)
		elif h < c:
			if a - p == 0:
				print(p * c)
			elif a - p < 0:
				print(a * c)
			elif a - p > 0:
				a = a - p
				tot += p * c
				if a - ch >= 0:
					print(tot + ch * h)
				elif a - ch < 0:
					print(tot + a * h)


n = int(input())
for i in range(n):
	s = 0
	(b, g, k) = [int(i) for i in input().split()]
	(cg, ck) = [int(i) for i in input().split()]
	b = b // 2
	if cg > ck:
		if b > g:
			s = cg * g
			b = b - g
		else:
			s = cg * b
			b = 0
		if b > k:
			s += ck * k
		else:
			s += ck * b
	else:
		if b > k:
			s = ck * k
			b = b - k
		else:
			s = ck * b
			b = 0
		if b > g:
			s += cg * g
		else:
			s += cg * b
	print(s)


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	k = 0
	if h > c and b > 0:
		k = h * min(b, p)
		b -= p
		if b > 0:
			k += c * min(f, b)
		print(k)
	elif h < c and b > 0:
		k = c * min(b, f)
		b -= f
		if b > 0:
			k += h * min(b, p)
		print(k)
	elif h == c and b > 0:
		k = c * min(b, f)
		b -= f
		if b > 0:
			k += h * min(b, p)
		print(k)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	ans = 0
	if h > c:
		s = min(b, p)
		ans += h * s
		b -= s
		p -= s
	else:
		s = min(b, f)
		ans += c * s
		b -= s
		f -= s
	if b and (p or f):
		s = min(b, max(p, f))
		if p:
			ans += h * s
			b -= s
			p -= s
		else:
			ans += c * s
			b -= s
			f -= s
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	(bun, beef, chi) = map(int, input().split())
	(h, c) = map(int, input().split())
	money = 0
	if h <= c:
		while chi > 0 and bun >= 2:
			money += c
			chi -= 1
			bun -= 2
		while beef > 0 and bun >= 2:
			money += h
			beef -= 1
			bun -= 2
	else:
		while beef > 0 and bun >= 2:
			money += h
			beef -= 1
			bun -= 2
		while chi > 0 and bun >= 2:
			money += c
			chi -= 1
			bun -= 2
	print(money)


list_of_solutions = []
a = int(input())
for i in range(a):
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	if l[0] < 2:
		list_of_solutions.append(0)
	else:
		profit = 0
		x = l[0]
		y = l[1]
		z = l[2]
		while x >= 2:
			if l1[0] >= l1[1] and y != 0:
				profit = profit + l1[0]
				x -= 2
				y -= 1
				if y == 0:
					l1[0] = 0
			elif l1[0] < l1[1] and z != 0:
				profit = profit + l1[1]
				x -= 2
				z -= 1
				if z == 0:
					l1[1] = 0
			else:
				break
		list_of_solutions.append(profit)
for i in list_of_solutions:
	print(i)


t = int(input())
for u in range(t):
	(b, p, f) = input().split()
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = input().split()
	(h, c) = (int(h), int(c))
	ham = 0
	chi = 0
	if h > c:
		while b > 1 and p > 0:
			ham += 1
			b -= 2
			p -= 1
		while b > 1 and f > 0:
			chi += 1
			b -= 2
			f -= 1
	else:
		while b > 1 and f > 0:
			chi += 1
			b -= 2
			f -= 1
		while b > 1 and p > 0:
			ham += 1
			b -= 2
			p -= 1
	ans = ham * h + chi * c
	print(ans)


def m3(a, b, c):
	return min(a, min(b, c))
tc = int(input())
while tc > 0:
	(n, m, t) = map(int, input().split())
	(p1, p2) = map(int, input().split())
	if n == 1:
		print('0')
	elif m + t <= int(n / 2):
		print(m * p1 + p2 * t)
	else:
		p = []
		for i in range(m3(int(n / 2), m, t) + 1):
			if i < int(n / 2) - max(m, t):
				pass
			elif m > t:
				p.append(i * p2 + (int(n / 2) - i) * p1)
			else:
				p.append(i * p1 + (int(n / 2) - i) * p2)
		p.sort()
		print(p[-1])
	tc -= 1


t = int(input())
for i in range(t):
	(buns, beef, chicken) = map(int, input().split())
	(bp, cp) = map(int, input().split())
	total = 0
	while buns > 1:
		if bp >= cp and beef > 0:
			total += bp
			beef -= 1
		elif cp >= bp and chicken > 0:
			total += cp
			chicken -= 1
		elif cp >= bp and chicken == 0 and (beef > 0):
			total += bp
			beef -= 1
		elif bp >= cp and beef == 0 and (chicken > 0):
			total += cp
			chicken -= 1
		buns -= 2
	print(total)


T = int(input())
for i in range(T):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	ans = 0
	if h > c:
		bur = min(b // 2, p)
		ans += h * bur
		b -= bur * 2
		ans += min(b // 2, f) * c
	else:
		fish = min(b // 2, f)
		ans += c * fish
		b -= fish * 2
		ans += min(b // 2, p) * h
	print(ans)


t = int(input())
for _ in range(t):
	(b, h, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	profit = 0
	if x > y:
		hb = min(h, b // 2)
		b -= hb * 2
		profit += hb * x
		profit += min(c, b // 2) * y
	else:
		cb = min(c, b // 2)
		b -= cb * 2
		profit += cb * y
		profit += min(h, b // 2) * x
	print(profit)


k = int(input())
for i in range(k):
	(bulki, cows, chickens) = input().split(' ')
	(priceCows, priceChicks) = input().split(' ')
	bulki = int(bulki)
	cows = int(cows)
	chickens = int(chickens)
	cash = 0
	priceCows = int(priceCows)
	priceChicks = int(priceChicks)
	if priceCows >= priceChicks:
		for j in range(cows):
			if bulki >= 2:
				bulki -= 2
			else:
				break
			cows -= 1
			cash += priceCows
		for j in range(chickens):
			if bulki >= 2:
				bulki -= 2
			else:
				break
			chickens -= 1
			cash += priceChicks
	else:
		for j in range(chickens):
			if bulki >= 2:
				bulki -= 2
			else:
				break
			chickens -= 1
			cash += priceChicks
		for j in range(cows):
			if bulki >= 2:
				bulki -= 2
			else:
				break
			cows -= 1
			cash += priceCows
	print(cash)


t = int(input())
stck = ''
cost = ''
for i in range(0, t):
	earn = 0
	stck = input()
	cost = input()
	stcksp = stck.split()
	b = int(stcksp[0])
	p = int(stcksp[1])
	f = int(stcksp[2])
	costsp = cost.split()
	h = int(costsp[0])
	c = int(costsp[1])
	if h > c:
		if p * 2 > b:
			n = b // 2
			earn = earn + n * h
			b = b - n * 2
			if f * 2 > b:
				n = b // 2
				earn = earn + n * c
			else:
				earn = earn + f * c
		else:
			earn = earn + p * h
			b = b - p * 2
			if f * 2 > b:
				n = b // 2
				earn = earn + n * c
			else:
				earn = earn + f * c
	elif f * 2 > b:
		n = b // 2
		earn = earn + n * c
		b = b - n * 2
		if p * 2 > b:
			n = b // 2
			earn = earn + n * h
		else:
			earn = earn + p * h
	else:
		earn = earn + f * c
		b = b - f * 2
		if p * 2 > b:
			n = b // 2
			earn = earn + n * h
		else:
			earn = earn + p * h
	print(earn)


t = int(input())
for i in range(t):
	(b, g, k) = (int(x) for x in input().split(' '))
	(h, p) = (int(x) for x in input().split(' '))
	price = 0
	if h < p:
		(g, k) = (k, g)
		(h, p) = (p, h)
	if g <= b // 2:
		price += g * h
		b -= g * 2
		if k <= b // 2:
			price += k * p
		else:
			price += b // 2 * p
	else:
		price += b // 2 * h
	print(price)


def profit(b, p, f, h, c):
	b //= 2
	if b >= p + f:
		return p * h + f * c
	if h > c:
		if b <= p:
			return b * h
		b -= p
		return p * h + b * c
	if b <= f:
		return b * c
	b -= f
	return b * h + f * c
t = int(input())
for _ in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	print(profit(b, p, f, h, c))


for _ in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	b = b // 2
	if h >= c:
		hb = min(b, p)
		b = b - hb
		cb = 0
		if b > 0:
			cb = min(b, f)
	else:
		(p, f) = (f, p)
		(c, h) = (h, c)
		hb = min(b, p)
		b = b - hb
		cb = 0
		if b > 0:
			cb = min(b, f)
	print(h * hb + c * cb)


t = int(input())
for i in range(t):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if c >= h and f <= b // 2 and (p >= b // 2 - f):
		print(c * f + h * (b // 2 - f))
	elif c >= h and f <= b // 2 and (p < b // 2 - f):
		print(c * f + h * p)
	elif c >= h and f > b // 2:
		print(c * (b // 2))
	elif c < h and p <= b // 2 and (f >= b // 2 - p):
		print(h * p + c * (b // 2 - p))
	elif c < h and p <= b // 2 and (f < b // 2 - p):
		print(h * p + c * f)
	elif c < h and p > b // 2:
		print(h * (b // 2))


t = int(input())
for test in range(t):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	nob = b // 2
	ans = 0
	if h > c:
		while p != 0 and nob != 0:
			ans += h
			p -= 1
			nob -= 1
		while f != 0 and nob != 0:
			ans += c
			f -= 1
			nob -= 1
	else:
		while f != 0 and nob != 0:
			ans += c
			f -= 1
			nob -= 1
		while p != 0 and nob != 0:
			ans += h
			p -= 1
			nob -= 1
	print(ans)


n = int(input())
for i in range(n):
	x = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		tmp = min(b // 2, p)
		tmp2 = b // 2 - tmp
		x += tmp * h
		x += min(tmp2, f) * c
	else:
		tmp = min(b // 2, f)
		tmp2 = b // 2 - tmp
		x += tmp * c
		x += min(tmp2, p) * h
	print(x)


t = int(input())
L = []
for i in range(t):
	[b, p, f] = [int(x) for x in input().split()]
	[h, c] = [int(x) for x in input().split()]
	if h > c:
		L.append(h * min(b // 2, p) + c * min((b - 2 * min(b // 2, p)) // 2, f))
	else:
		L.append(c * min(b // 2, f) + h * min((b - 2 * min(b // 2, f)) // 2, p))
for i in L:
	print(i)


from sys import stdin
A = int(stdin.readline())
for t in range(0, A):
	B = list(map(int, stdin.readline().split()))
	C = list(map(int, stdin.readline().split()))
	if C[0] > C[1]:
		K = min(B[0] // 2, B[1])
		if B[1] < B[0] // 2:
			L = min(B[0] // 2 - B[1], B[2])
		else:
			L = 0
		print(C[0] * K + L * C[1])
	else:
		K = min(B[0] // 2, B[2])
		if B[2] < B[0] // 2:
			L = min(B[0] // 2 - B[2], B[1])
		else:
			L = 0
		print(C[1] * K + L * C[0])


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	burgers = b // 2
	for n in range(burgers + 1):
		m = burgers - n
		new_profit = h * min(n, p) + c * min(m, f)
		profit = max(profit, new_profit)
	print(profit)


import math
q = int(input())
while q:
	(bun, beef, cutlet) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = bun // 2
	if b <= beef and b <= cutlet:
		print(max(h, c) * b)
	elif h > c:
		A = min(b, beef)
		B = b - beef
		if B < 0:
			B = 0
		price = A * h + min(B, cutlet) * c
		print(price)
	else:
		A = min(b, cutlet)
		B = b - cutlet
		if B < 0:
			B = 0
		price = A * c + min(B, beef) * h
		print(price)
	q = q - 1


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	c1 = 0
	h1 = 0
	if c > h:
		c1 += min(b // 2, f)
		b -= c1 * 2
		h1 += min(b // 2, p)
	else:
		h1 += min(b // 2, p)
		b -= h1 * 2
		c1 += min(b // 2, f)
	print(c1 * c + h1 * h)


no = int(input())
resi = []
for i in range(no):
	(b, beef, chicken) = map(int, input().split())
	(ham, chick) = map(int, input().split())
	no_burger = b // 2
	if ham < chick:
		(ham, chick) = (chick, ham)
		(beef, chicken) = (chicken, beef)
	count = 0
	res = min(no_burger, beef)
	no_burger = no_burger - res
	count = count + res * ham
	res = min(no_burger, chicken)
	no_burger = no_burger - res
	count = count + res * chick
	resi.append(count)
for i in resi:
	print(i)


import sys
input = lambda : sys.stdin.readline().strip()
T = int(input())
for i in range(T):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	Max = 0
	if h >= c:
		Max += min(p, b // 2) * h
		b -= 2 * min(p, b // 2)
		Max += min(f, b // 2) * c
	else:
		Max += min(f, b // 2) * c
		b -= 2 * min(f, b // 2)
		Max += min(p, b // 2) * h
	print(Max)


x = int(input())
lst = []
for i in range(0, x):
	(b, p, f) = map(int, input().split())
	(h, e) = map(int, input().split())
	b //= 2
	if h > e:
		c = min(b, p)
		sum = c * h
		b -= c
		sum += min(b, f) * e
		lst.append(sum)
	else:
		c = min(b, f)
		sum = c * e
		b -= c
		sum += min(b, p) * h
		lst.append(sum)
print(*lst, sep='\n')


t = int(input())
for i in range(0, t):
	ln = [int(j) for j in input().split(' ')]
	b = ln[0]
	p = ln[1]
	f = ln[2]
	ln = [int(j) for j in input().split(' ')]
	h = ln[0]
	c = ln[1]
	b = b // 2
	m = 0
	if h > c:
		mn = min(b, p)
		m += mn * h
		b -= mn
		mn = min(b, f)
		m += mn * c
		b -= mn
	else:
		mn = min(b, f)
		m += mn * c
		b -= mn
		mn = min(b, p)
		m += mn * h
		b -= mn
	print(m)


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 6)
input = stdin.readline
t = int(input().rstrip())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pan = b // 2
	ans = 0
	for i in range(pan + 1):
		for j in range(pan - i + 1):
			ans = max(ans, min(i, p) * h + min(j, f) * c)
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	buns = b // 2
	if buns >= p + f:
		print(p * h + f * c)
	else:
		hamburger = min(p, buns)
		chickenburger = buns - hamburger
		(Chicken, ans) = (min(f, buns), 0)
		while hamburger >= buns - Chicken and chickenburger <= Chicken:
			ans = max(ans, hamburger * h + chickenburger * c)
			hamburger -= 1
			chickenburger += 1
		print(ans)


import math

def solve(test):
	ans = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	c1 = 0
	c2 = 0
	if h > c:
		c1 = min(p, b // 2)
		p -= c1
		b -= 2 * c1
	elif h < c:
		c2 = min(f, b // 2)
		f -= c2
		b -= 2 * c2
	ans = c1 * h + c2 * c
	c1 = min(p, b // 2)
	p -= c1
	b -= 2 * c1
	c2 = min(f, b // 2)
	f -= c2
	b -= 2 * c2
	ans += h * c1 + c * c2
	print(ans)
t = int(input())
for _ in range(t):
	solve(_ + 1)


for i in range(int(input())):
	(b, p, q) = map(int, input().split())
	(h, c) = map(int, input().split())
	li = sorted([[h, p], [c, q]])[::-1]
	n = b // 2
	if n <= li[0][1]:
		print(li[0][0] * n)
	elif n > li[0][1] and n <= li[0][1] + li[1][1]:
		a = n - li[0][1]
		print(li[0][0] * li[0][1] + li[1][0] * a)
	else:
		print(li[0][0] * li[0][1] + li[1][0] * li[1][1])


T = int(input())
s = lambda : list(map(int, input().split()))
for tc in range(T):
	(b, p, f) = s()
	(h, c) = s()
	if h < c:
		(h, c) = (c, h)
		(f, p) = (p, f)
	b = b // 2
	print(h * min(b, p) + c * min(b - min(b, p), f))


def sortSecond(val):
	return val[1]
t = int(input())
for i in range(0, t):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	list1dic = [(p, h), (f, c)]
	list1dic.sort(key=sortSecond, reverse=True)
	range1 = b + 1
	profit = 0
	if 1 <= b and f <= 100 and (1 <= h) and (c <= 100):
		for i in list1dic:
			dummy = i[0] + 1
			range1 = b + 1
			while range1 > b:
				dummy = dummy - 1
				range1 = dummy * 2
			b = b - range1
			profit = dummy * i[1] + profit
		print(profit)
	else:
		print('Error in input')


n = int(input())
a = []
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pn = 0
	fn = 0
	if c > h:
		if b >= 2 * f:
			fn = f
			b = b - 2 * f
			if b >= 2 * p:
				pn = p
			else:
				pn = b // 2
		else:
			fn = b // 2
	elif b >= 2 * p:
		pn = p
		b = b - 2 * p
		if b >= 2 * f:
			fn = f
		else:
			fn = b // 2
	else:
		pn = b // 2
	profit = fn * c + pn * h
	a.append(profit)
for i in range(n):
	print(a[i])


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getArr():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(b, p, f) = getVars()
	(h, c) = getVars()
	if h > c:
		res = min(p, b // 2) * h
		b -= min(p, b // 2) * 2
		res += min(f, b // 2) * c
	else:
		res = min(f, b // 2) * c
		b -= min(f, b // 2) * 2
		res += min(p, b // 2) * h
	print(res)


from sys import stdin
_input = stdin.readline
(_range, _min, _int) = (range, min, int)

def solution():
	for _ in _range(_int(_input())):
		(b, p, f) = [_int(i) for i in _input().split()]
		(h, c) = [_int(i) for i in _input().split()]
		ans = 0
		bread = b // 2
		if bread == 0:
			print(0)
			continue
		if h > c:
			temp = _min(bread, p)
			ans += temp * h
			bread -= temp
			p -= temp
			ans += _min(bread, f) * c
			print(ans)
		else:
			temp = _min(bread, f)
			ans += temp * c
			bread -= temp
			f -= temp
			ans += _min(bread, p) * h
			print(ans)
solution()


t = int(input())
for i in range(t):
	(paes, bife, galinha) = map(int, input().split())
	(b, g) = map(int, input().split())
	dinheiros = 0
	paes = paes // 2
	if b > g:
		for i in range(paes):
			if bife != 0:
				dinheiros += b
				bife -= 1
			elif galinha != 0:
				dinheiros += g
				galinha -= 1
	else:
		for i in range(paes):
			if galinha != 0:
				dinheiros += g
				galinha -= 1
			elif bife != 0:
				dinheiros += b
				bife -= 1
	print(dinheiros)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	b //= 2
	(h, c) = map(int, input().split())
	result = 0
	if h > c:
		cnt = min(p, b)
		result += h * cnt
		cnt = min(f, b - cnt)
		result += c * cnt
	else:
		cnt = min(f, b)
		result += c * cnt
		cnt = min(p, b - cnt)
		result += h * cnt
	print(result)


t = int(input())
for i in range(t):
	(buns, max_meat, min_meat) = map(int, input().split(' '))
	(max_profit, min_profit) = map(int, input().split(' '))
	if min_profit > max_profit:
		(max_profit, min_profit) = (min_profit, max_profit)
		(max_meat, min_meat) = (min_meat, max_meat)
	buns = buns // 2
	profit = 0
	if buns <= max_meat:
		profit += buns * max_profit
	else:
		profit += max_meat * max_profit
		buns -= max_meat
		profit += min(buns, min_meat) * min_profit
	print(profit)


n = int(input())
for k in range(n):
	a = list(map(int, input().split()))
	g = list(map(int, input().split()))
	p = 0
	if a[0] == 1:
		print(0)
	else:
		l = a[0] // 2
		if g[0] == g[1]:
			if a[1] + a[2] > l:
				p = l * g[1]
			else:
				p = (a[1] + a[2]) * g[1]
		else:
			for x in range(l):
				t = g.index(max(g))
				if a[1] == 0 and a[2] == 0:
					break
				elif a[t + 1] > 0:
					p += g[t]
					a[t + 1] -= 1
				else:
					p += g[g.index(min(g))]
					a[g.index(min(g)) + 1] -= 1
		print(p)


n = int(input())
ans = []
for i in range(n):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	buns_pair = b // 2
	if h < c:
		x = min(buns_pair, f)
		buns_pair -= x
		ans.append(x * c + min(buns_pair, p) * h)
	else:
		x = min(buns_pair, p)
		buns_pair -= x
		ans.append(x * h + min(buns_pair, f) * c)
for i in ans:
	print(i)


from math import *
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	nb = floor(b / 2)
	if h >= c:
		if nb >= p:
			print(p * h + min(nb - p, f) * c)
		else:
			print(nb * h)
	elif nb >= f:
		print(f * c + min(nb - f, p) * h)
	else:
		print(nb * c)


q = int(input())
for _ in range(q):
	(a, b, c) = list(map(int, input().split()))
	(d, e) = list(map(int, input().split()))
	if a & 1:
		a = a - 1
	if a >= 2 * (b + c):
		print(b * d + c * e)
	else:
		l = 0
		if d > e:
			if a >= 2 * b:
				l += b * d
				a = a - 2 * b
				l += a // 2 * e
			else:
				l += a // 2 * d
			print(l)
		elif e > d:
			if a >= 2 * c:
				l += c * e
				a = a - 2 * c
				l += a // 2 * d
			else:
				l += a // 2 * e
			print(l)
		else:
			print(a // 2 * d)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if h >= c:
		(maxx, minn, maxp, minp) = (p, f, h, c)
	else:
		(maxx, minn, maxp, minp) = (f, p, c, h)
	if b // 2 == 0:
		print(0)
	elif b // 2 >= p + f:
		print(p * h + f * c)
	elif b // 2 >= maxx:
		print(maxx * maxp + (b // 2 - maxx) * minp)
	else:
		print(b // 2 * maxp)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	a_ham = min(b // 2, p)
	a_bur = min((b - 2 * a_ham) // 2, f)
	a_prof = a_ham * h + a_bur * c
	b_bur = min(b // 2, f)
	b_ham = min((b - 2 * b_bur) // 2, p)
	b_prof = b_ham * h + b_bur * c
	print(max(a_prof, b_prof))


q = int(input())
ans = []
for i in range(q):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	num_sam = b // 2
	total = 0
	if h > c:
		while num_sam > 0:
			if p > 0:
				total += h
				num_sam -= 1
				p -= 1
			elif f > 0:
				total += c
				num_sam -= 1
				f -= 1
			else:
				break
	else:
		while num_sam > 0:
			if f > 0:
				total += c
				num_sam -= 1
				f -= 1
			elif p > 0:
				total += h
				num_sam -= 1
				p -= 1
			else:
				break
	ans.append(total)
for a in ans:
	print(a)


def ans(b, p, f, h, c):
	costmax = 0
	fo = []
	for x in range(0, min(b // 2, p) + 1):
		for y in range(0, min(b // 2, f) + 1):
			if 2 * x + 2 * y <= b:
				co = x * h + y * c
				fo.append(co)
	return max(fo)
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(ans(b, p, f, h, c))


for _ in range(int(input())):
	x = list(map(int, input().split()))
	p = list(map(int, input().split()))
	(Min, Max, n) = (min(p), max(p), 0)
	n = min(x[p.index(Max) + 1], x[0] // 2)
	x[0] -= n * 2
	n *= Max
	n += min(x[p.index(Min) + 1], x[0] // 2) * Min
	print(n)


import sys
n = int(input())
while n > 0:
	n -= 1
	(b, p, f) = map(int, sys.stdin.readline().split())
	(h, c) = map(int, sys.stdin.readline().split())
	if b < 2:
		print(0)
		continue
	if c > h:
		profit = 0
		t = f
		while t * 2 > b:
			t -= 1
		b -= t * 2
		profit += t * c
		t = p
		while t * 2 > b:
			t -= 1
		b -= t * 2
		profit += t * h
		print(profit)
		continue
	else:
		profit = 0
		t = p
		while t * 2 > b:
			t -= 1
		b -= t * 2
		profit += t * h
		t = f
		while t * 2 > b:
			t -= 1
		b -= t * 2
		profit += t * c
		print(profit)


N = int(input())
for i in range(N):
	temp = input().split()
	b = int(temp[0])
	p = int(temp[1])
	f = int(temp[2])
	temp = input().split()
	h = int(temp[0])
	c = int(temp[1])
	if h >= c:
		if 2 * p > b:
			out = b // 2 * h
		else:
			out = p * h
			res = min((b - 2 * p) // 2, f)
			out += res * c
	elif 2 * f > b:
		out = b // 2 * c
	else:
		out = f * c
		res = min((b - 2 * f) // 2, p)
		out += res * h
	print(out)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(pp, fp) = map(int, input().split())
	money = 0
	if b > 2 * max(p, f):
		tb = b
		if pp > fp:
			tb -= 2 * p
			money += pp * p
			money += min(tb // 2, f) * fp
		else:
			tb -= 2 * f
			money += fp * f
			money += min(tb // 2, p) * pp
	else:
		tb = b
		if pp > fp:
			money += min(tb // 2, p) * pp
			tb -= min(tb // 2, p) * 2
			money += min(tb // 2, f) * fp
		else:
			money += min(tb // 2, f) * fp
			tb -= min(tb // 2, f) * 2
			money += min(tb // 2, p) * pp
	print(money)


t = int(input())
while t:
	res = 0
	(b, p, f) = map(int, input().split())
	(p1, p2) = map(int, input().split())
	b = b // 2
	if p1 < p2:
		if b >= f:
			b -= f
			res += f * p2
		else:
			res += b * p2
			b = 0
		if b >= p:
			b -= p
			res += p * p1
		else:
			res += b * p1
			b = 0
	else:
		if b >= p:
			b -= p
			res += p * p1
		else:
			res += b * p1
			b = 0
		if b >= f:
			b -= f
			res += f * p2
		else:
			res += b * p2
			b = 0
	print(res)
	t -= 1


for i in range(int(input())):
	(p, h, c) = map(int, input().split())
	(h1, c1) = map(int, input().split())
	m = 0
	(y, x) = (0, 0)
	if p >= 2:
		if h1 < c1:
			while y != 1:
				if c != 0 and p >= 2:
					c -= 1
					p -= 2
					m += c1
				else:
					y = 1
			while x != 1:
				if h != 0 and p >= 2:
					h -= 1
					p -= 2
					m += h1
				else:
					x = 1
		else:
			while y != 1:
				if h != 0 and p >= 2:
					h -= 1
					p -= 2
					m += h1
				else:
					y = 1
			while x != 1:
				if c != 0 and p >= 2:
					c -= 1
					p -= 2
					m += c1
				else:
					x = 1
	print(m)


import sys
t = int(input())
for q in range(t):
	(b, ham, chik) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if h >= c:
		ham = min(ham, b)
		b = b - ham
		chik = min(chik, b)
	if c > h:
		chik = min(chik, b)
		b = b - chik
		ham = min(ham, b)
	p = 0
	p = ham * h + chik * c
	print(p)


for _ in range(int(input())):
	(b, p, c) = map(int, input().split())
	(pc, cc) = map(int, input().split())
	to = b // 2
	if b < 2:
		print(0)
	elif p + c <= to:
		print(p * pc + c * cc)
	elif pc >= cc:
		if p >= to:
			print(to * pc)
		else:
			k = abs(p - to)
			if c >= k:
				print(p * pc + k * cc)
			else:
				print(p * pc + c * cc)
	elif c >= to:
		print(to * cc)
	else:
		k = abs(c - to)
		if p >= k:
			print(k * pc + c * cc)
		else:
			print(p * pc + c * cc)


t = int(input())
for i in range(t):
	tot = 0
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	while b > 1:
		if h > c and p != 0:
			tot += h
			p -= 1
		elif f != 0:
			tot += c
			f -= 1
		elif p != 0:
			tot += h
			p -= 1
		b -= 2
	print(tot)


ans = []
for i in range(int(input())):
	(available, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		ans.append(h * (available // 2) if available // 2 < p else h * p + min(available // 2 - p, f) * c)
	else:
		ans.append(c * (available // 2) if available // 2 < f else f * c + min(available // 2 - f, p) * h)
for i in ans:
	print(i)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(h, f) = map(int, input().split())
	print(max(min(b, a // 2) * h + min(max(0, a - min(b, a // 2) * 2) // 2, c) * f, min(c, a // 2) * f + min(max(0, a - min(c, a // 2) * 2) // 2, b) * h))


t = int(input())
for i in range(t):
	lista = list(map(int, input().split(' ')))
	precios = list(map(int, input().split(' ')))
	dinero = 0
	if precios[0] > precios[1]:
		cuantas = lista[0] // 2
		puedo = min(cuantas, lista[1])
		dinero = puedo * precios[0]
		cuantas -= puedo
		puedo = min(cuantas, lista[2])
		dinero += puedo * precios[1]
	else:
		cuantas = lista[0] // 2
		puedo = min(cuantas, lista[2])
		dinero = puedo * precios[1]
		cuantas -= puedo
		puedo = min(cuantas, lista[1])
		dinero += puedo * precios[0]
	print(dinero)


t = int(input())
ans = []
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	for i in range(p + 1):
		for j in range(f + 1):
			if 2 * i + 2 * j <= b:
				res = max(res, i * h + j * c)
	ans.append(res)
print(*ans, sep='\n')


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, d) = map(int, input().split())
	bur = b // 2
	cost = 0
	if bur == 0:
		print(0)
		continue
	elif h > d:
		if bur > p:
			bur -= p
			cost = p * h
			if bur > f:
				bur -= f
				cost += f * d
			else:
				cost += bur * d
				bur = 0
		else:
			cost = bur * h
			bur = 0
	elif bur > f:
		bur -= f
		cost = f * d
		if bur > p:
			bur -= p
			cost += p * h
		else:
			cost += bur * h
			bur = 0
	else:
		cost = bur * d
		bur = 0
	print(cost)


for _ in range(int(input())):
	(m, b, f) = map(int, input().split())
	(a, c) = map(int, input().split())
	if a > c:
		if b > m // 2:
			print(m // 2 * a)
		else:
			print(b * a + min(m // 2 - b, f) * c)
	elif f > m // 2:
		print(m // 2 * c)
	else:
		print(f * c + min(m // 2 - f, b) * a)


q = int(input())
d = 0
for i in range(q):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	for j in range(min(b // 2, p + f)):
		if c > h and j < f:
			d += c
		elif c > h and j >= f:
			d += h
		elif h > c and j < p:
			d += h
		elif h > c and j >= p:
			d += c
		elif h == c:
			d += h
	print(d)
	d = 0


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(hp, cp) = map(int, input().split())
	prof = 0
	if hp > cp:
		h = min(p, b // 2)
		prof += h * hp
		b -= 2 * h
		c = min(f, b // 2)
		prof += c * cp
	else:
		c = min(f, b // 2)
		prof += c * cp
		b -= 2 * c
		h = min(p, b // 2)
		prof += h * hp
	print(prof)


nTestes = int(input())
for i in range(nTestes):
	lucro = 0
	bpf = input().split()
	b = int(bpf[0])
	p = int(bpf[1])
	f = int(bpf[2])
	hc = input().split()
	h = int(hc[0])
	c = int(hc[1])
	bUsavel = b // 2
	if h > c:
		hamburguers = min(bUsavel, p)
		lucro += hamburguers * h
		bUsavel -= hamburguers
		hamburguers = min(bUsavel, f)
		lucro += hamburguers * c
	else:
		hamburguers = min(bUsavel, f)
		lucro += hamburguers * c
		bUsavel -= hamburguers
		hamburguers = min(bUsavel, p)
		lucro += hamburguers * h
	print(lucro)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	profit = 0
	if c > h:
		nb_chicken_burger = min(f, b // 2)
		profit += nb_chicken_burger * c
		b -= nb_chicken_burger * 2
		nb_hamburger = min(p, b // 2)
		profit += nb_hamburger * h
	else:
		nb_hamburger = min(p, b // 2)
		profit += nb_hamburger * h
		b -= nb_hamburger * 2
		nb_chicken_burger = min(f, b // 2)
		profit += nb_chicken_burger * c
	print(profit)


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	maxi = 0
	for x in range(0, p + 1):
		hleft = b - 2 * x
		ch = min(hleft // 2, f)
		prof = x * h + ch * c
		if maxi < prof and x >= 0 and (ch >= 0) and (hleft >= 0):
			maxi = prof
	print(maxi)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ma = b // 2
	k = 0
	if h > c:
		while ma > 0 and p > 0:
			ma -= 1
			p -= 1
			k += h
		while ma > 0 and f > 0:
			ma -= 1
			f -= 1
			k += c
	else:
		while ma > 0 and f > 0:
			ma -= 1
			f -= 1
			k += c
		while ma > 0 and p > 0:
			ma -= 1
			p -= 1
			k += h
	print(k)


def maxprofit(buns, patties, cutlets, burgprofit, cutprofit):
	if buns < 2:
		return 0
	if buns % 2 != 0:
		buns = buns - 1
	if buns / 2 >= patties + cutlets:
		return burgprofit * patties + cutlets * cutprofit
	profit = 0
	while patties + cutlets > 0 and buns > 0:
		if burgprofit >= cutprofit:
			if patties > 0:
				profit += burgprofit
				buns -= 2
				patties -= 1
				continue
			profit += cutprofit
			buns -= 2
			cutlets -= 1
		if burgprofit < cutprofit:
			if cutlets > 0:
				profit += cutprofit
				buns -= 2
				cutlets -= 1
				continue
			profit += burgprofit
			buns -= 2
			patties -= 1
	return profit
queries = input()
for x in range(int(queries)):
	(b, p, c) = input().split(' ')
	(bp, cp) = input().split(' ')
	print(maxprofit(int(b), int(p), int(c), int(bp), int(cp)))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	a = a // 2
	if d >= e:
		pro = min(a, b)
		f = pro * d
		a -= pro
		if a > 0:
			pro = min(a, c)
			f = f + pro * e
		print(f)
	else:
		pro = min(a, c)
		f = pro * e
		a -= pro
		if a > 0:
			pro = min(a, b)
			f = f + pro * d
		print(f)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b % 2:
		b -= 1
	ans = 0
	if h > c:
		next = min(b // 2, p)
		ans += h * next
		b -= next * 2
		ans += min(b // 2, f) * c
	else:
		next = min(b // 2, f)
		ans += c * next
		b -= next * 2
		ans += min(b // 2, p) * h
	print(ans)


number = int(input())
result_list = list()
for i in range(number):
	burger = 0
	chicken = 0
	(x, y, z) = map(int, input().split())
	(a, b) = map(int, input().split())
	if x == 1:
		result_list.append(0)
	else:
		if a > b:
			while x > 1 and y != 0:
				burger += 1
				y -= 1
				x -= 2
			if x > 1:
				while x > 1 and z != 0:
					chicken += 1
					x -= 2
					z -= 1
		elif b > a:
			while x > 1 and z != 0:
				chicken += 1
				x -= 2
				z -= 1
			if x > 1:
				while x > 1 and y != 0:
					burger += 1
					x -= 2
					y -= 1
		elif y >= z:
			while x > 1 and y != 0:
				burger += 1
				x -= 2
				y -= 1
			while x > 1 and z != 0:
				chicken += 1
				x -= 2
				z -= 1
		else:
			while x > 1 and z != 0:
				x -= 2
				z -= 1
				chicken += 1
			while x > 1 and y != 0:
				x -= 2
				y -= 1
				burger += 1
		result_list.append(burger * a + chicken * b)
for result in result_list:
	print(result)


q = int(input())
for i in range(q):
	ints = [int(x) for x in input().split()]
	ints2 = [int(x) for x in input().split()]
	buns = ints[0]
	ans = 0
	if ints2[0] > ints2[1]:
		a = min(buns // 2, ints[1])
		ans += ints2[0] * a
		buns = buns - a * 2
		ans += ints2[1] * min(buns // 2, ints[2])
	else:
		a = min(buns // 2, ints[2])
		ans += ints2[1] * a
		buns = buns - a * 2
		ans += ints2[0] * min(buns // 2, ints[1])
	print(ans)


t = int(input())
for ss in range(t):
	(b, p, f) = input().split()
	(h, c) = input().split()
	(b, p, f, h, c) = (int(b), int(p), int(f), int(h), int(c))
	ans = 0
	if b == 1:
		print(0, end='\n')
		continue
	if h > c:
		if b // 2 > p:
			ans += p * h
			b -= p * 2
			p = 0
			if b // 2 > 0:
				ans += min(b // 2, f) * c
		else:
			ans += b // 2 * h
			p -= b // 2
			b -= b // 2 * 2
			if b > 1:
				ans += min(p, f) * c
	elif b // 2 > f:
		ans += f * c
		b -= f * 2
		f = 0
		if b // 2 > 0:
			ans += min(b // 2, p) * h
	else:
		ans += b // 2 * c
		f -= b // 2
		b -= b // 2 * 2
		if b > 1:
			ans += min(f, p) * h
	print(ans, end='\n')


t = int(input())
while t != 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		max1 = h
		c1 = p
		max2 = c
		c2 = f
	else:
		max1 = c
		c1 = f
		max2 = h
		c2 = p
	mid = b // 2
	m = 1
	sum = 0
	while mid != 0 and c1 != 0:
		sum += max1 * m
		mid = mid - 1
		c1 = c1 - 1
	while mid != 0 and c2 != 0:
		sum += max2 * m
		mid = mid - 1
		c2 = c2 - 1
	print(sum)
	t = t - 1


from sys import stdin
n = int(stdin.readline().strip())
for i in range(n):
	(v, p, f) = list(map(int, stdin.readline().strip().split()))
	(h, c) = list(map(int, stdin.readline().strip().split()))
	ans = 0
	for j in range(101):
		for k in range(101):
			(v1, p1, f1) = (v, p, f)
			v1 -= 2 * j
			p1 -= j
			v1 -= 2 * k
			f1 -= k
			if v1 >= 0 and p1 >= 0 and (f1 >= 0):
				ans = max(ans, h * j + c * k)
	print(ans)


x = int(input())
for t in range(x):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	burgers = b // 2
	beef = 0
	chicken = 0
	while burgers > 0:
		if h > c:
			if p > 0:
				p -= 1
				beef += 1
				burgers -= 1
			if p == 0 and burgers > 0 and (f > 0):
				f -= 1
				chicken += 1
				burgers -= 1
			if f == 0 and p == 0:
				break
			ans = beef * h + chicken * c
		elif c >= h:
			if f > 0:
				f -= 1
				chicken += 1
				burgers -= 1
			if f == 0 and burgers > 0 and (p > 0):
				p -= 1
				beef += 1
				burgers -= 1
			if f == 0 and p == 0:
				break
	ans = beef * h + chicken * c
	print(ans)


def list_input():
	return list(map(int, input().split()))
t = int(input())
data = []
for i in range(t):
	data.append(list_input() + list_input())
for i in range(t):
	profit = 0
	while data[i][0] >= 2 and (data[i][1] >= 1 or data[i][2] >= 1):
		if data[i][4] > data[i][3]:
			if data[i][2] >= 1:
				data[i][2] -= 1
				profit += data[i][4]
			else:
				data[i][1] -= 1
				profit += data[i][3]
		elif data[i][1] >= 1:
			data[i][1] -= 1
			profit += data[i][3]
		else:
			data[i][2] -= 1
			profit += data[i][4]
		data[i][0] -= 2
	print(profit)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(b, p, f) = stdin.readline().strip().split(' ')
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = stdin.readline().strip().split(' ')
	(h, c) = (int(h), int(c))
	if h == c:
		bp = b // 2
		ans = min(bp, f + p) * h
	elif h > c:
		bp = b // 2
		ans = min(p, bp)
		p -= ans
		bp -= ans
		ans *= h
		ans += min(f, bp) * c
	else:
		bp = b // 2
		ans = min(f, bp)
		f -= ans
		bp -= ans
		ans *= c
		ans += min(p, bp) * h
	stdout.write(str(ans) + '\n')


q = int(input())
for query in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b % 2:
		b -= 1
	ans = 0
	if h > c:
		ans += h * min(p, b // 2)
		b -= min(p, b // 2) * 2
		ans += c * min(f, b // 2)
	else:
		ans += c * min(f, b // 2)
		b -= min(f, b // 2) * 2
		ans += h * min(p, b // 2)
	print(ans)


def calcMax(buns, b, c, bprof, cprof):
	profit = 0
	num = buns // 2
	if bprof >= cprof:
		if num >= b:
			profit += b * bprof
			num -= b
			profit += min(num, c) * cprof
		else:
			profit += num * bprof
	elif num >= c:
		profit += c * cprof
		num -= c
		profit += min(num, b) * bprof
	else:
		profit += num * cprof
	return profit

def main():
	n = int(input())
	for _ in range(n):
		(buns, b, c) = map(int, input().rstrip().split())
		(bprof, cprof) = map(int, input().rstrip().split())
		ans = calcMax(buns, b, c, bprof, cprof)
		print(ans)
main()


for _ in range(int(input())):
	cost = l = 0
	c1 = c2 = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		while b > 1 and p > 0:
			if b > 1 and f > 0:
				b -= 2
				f -= 1
				c1 += 1
			else:
				b -= 2
				p -= 1
				c2 += 1
		cost += c1 * c + c2 * h
	else:
		while b > 1 and f > 0:
			if b > 1 and p > 0:
				l += 1
				b -= 2
				p -= 1
				c1 += 1
			else:
				b -= 2
				f -= 1
				c2 += 1
		cost += c1 * h + c2 * c
	print(cost)


n = input()
n = int(n)
cost = []
for i in range(n):
	cost.append(0)
	(b, p, f) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	(h, c) = input().split()
	h = int(h)
	c = int(c)
	a = 2 * (p + f)
	if b >= a:
		cost[i] = cost[i] + p * h + f * c
	elif h > c:
		if p * 2 <= b:
			cost[i] = cost[i] + p * h
		else:
			while p * 2 > b:
				p = p - 1
			cost[i] = cost[i] + p * h
		b = b - 2 * p
		if f * 2 <= b:
			cost[i] = cost[i] + f * c
		else:
			while f * 2 > b:
				f = f - 1
		cost[i] = cost[i] + f * c
	else:
		if f * 2 <= b:
			cost[i] = cost[i] + f * c
		else:
			while f * 2 > b:
				f = f - 1
			cost[i] = cost[i] + f * c
		b = b - 2 * f
		if p * 2 <= b:
			cost[i] = cost[i] + p * h
		else:
			while p * 2 > b:
				p = p - 1
		cost[i] = cost[i] + p * h
for i in range(n):
	print(cost[i])


t = int(input())
for _ in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	result = 0
	if h > c:
		if p >= b // 2:
			result = h * (b // 2)
		else:
			result = h * p + min(f, (b - 2 * p) // 2) * c
	elif f >= b // 2:
		result = c * (b // 2)
	else:
		result = c * f + min(p, (b - 2 * f) // 2) * h
	print(result)


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ham = 0
	chick = 0
	profit = 0
	if h > c:
		ham = min(b // 2, p)
		b = b - ham * 2
		p = p - ham
		chick = min(b // 2, f)
	else:
		chick = min(b // 2, f)
		b = b - chick * 2
		f = f - chick
		ham = min(b // 2, p)
	profit = ham * h + c * chick
	print(profit)
	t = t - 1


t = int(input())
for i in range(0, t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b >= (p + f) * 2:
		profit = p * h + f * c
	else:
		nb = b // 2
		if c > h and f >= nb:
			profit = c * nb
		if c > h and f < nb:
			profit = c * f + h * (nb - f)
		if h >= c and p > nb:
			profit = h * nb
		if h >= c and p <= nb:
			profit = h * p + c * (nb - p)
		if nb == 0:
			profit = 0
	print(profit)


t = int(input())
while t:
	(b, p, c) = map(int, input().split())
	(h, ch) = map(int, input().split())
	if b >= 2 * (p + c):
		print(h * p + ch * c)
	elif b >= max(p, c) * 2:
		if h > ch:
			print(h * p + (b - 2 * p) // 2 * ch)
		else:
			print(ch * c + (b - 2 * c) // 2 * h)
	elif 2 * min(p, c) <= b < max(p, c) * 2:
		if h > ch:
			b = b // 2
			print(h * min(p, b) + ch * (b - min(p, b)))
		else:
			b = b // 2
			print(ch * min(c, b) + h * (b - min(c, b)))
	elif b < 2 * min(p, c):
		b = b // 2
		if h > ch:
			print(h * b)
		else:
			print(ch * b)
	t = t - 1


from sys import stdin, stdout
t = int(input())
for i in range(t):
	(b, p, f) = [int(x) for x in stdin.readline().split()]
	(h, c) = [int(x) for x in stdin.readline().split()]
	b = (b - 1) // 2 if b & 1 else b // 2
	mp = 0
	m = []
	if c > h:
		x = min(b, f)
		mp += c * x
		b -= x
		f -= x
		y = min(b, p)
		mp += y * h
		m.append(mp)
	else:
		x = min(b, p)
		mp += x * h
		b -= x
		p -= x
		y = min(b, f)
		mp += y * c
		m.append(mp)
	print(*m, sep='\n')


t = int(input())
for you in range(t):
	l = input().split()
	b = int(l[0])
	p = int(l[1])
	f = int(l[2])
	l = input().split()
	h = int(l[0])
	c = int(l[1])
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	ans = 0
	ans += h * min(b // 2, p)
	b -= 2 * min(b // 2, p)
	ans += c * min(b // 2, f)
	print(ans)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	val = max(h, c)
	vval = min(h, c)
	cost = 0
	if val == h:
		first = p
		second = f
	else:
		first = f
		second = p
	if first * 2 <= b:
		b -= 2 * first
		cost += first * val
	else:
		cost += b // 2 * val
		b -= b // 2 * 2
	if second * 2 <= b:
		b -= 2 * second
		cost += second * vval
	elif b <= 1:
		cost = cost
	else:
		cost += b // 2 * vval
	print(cost)


q = int(input())
for i in range(q):
	(b, p, f) = map(int, input().strip().split(' '))
	(h, c) = map(int, input().strip().split(' '))
	m = min(p + f, b // 2)
	r = 0
	if c > h:
		if f > m:
			r += m * c
		else:
			r += f * c
			r += (m - f) * h
	elif c < h:
		if p > m:
			r += m * h
		else:
			r += p * h
			r += (m - p) * c
	else:
		r += m * c
	print(r)


def solve(b, p, f, h, c):
	b //= 2
	if h >= c:
		k = min(b, p)
		b -= k
		i = min(b, f)
		return k * h + i * c
	else:
		i = min(b, f)
		b -= i
		k = min(b, p)
		return k * h + i * c

def main():
	n = int(input())
	for _ in range(n):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		print(solve(b, p, f, h, c))
main()


import math
n = int(input())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	ans = max(min(b, p) * h + min(b - min(b, p), f) * c, min(b, f) * c + min(b - min(b, f), p) * h)
	print(ans)


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		if b >= 2 * p:
			b = b - 2 * p
			x = p * h
			y = b // 2
			val = min(y, f) * c
			print(x + val)
		else:
			y = b // 2
			val = min(y, p)
			print(val * h)
	elif b >= 2 * f:
		b = b - 2 * f
		x = f * c
		y = b // 2
		val = min(y, p) * h
		print(x + val)
	else:
		y = b // 2
		val = min(y, f)
		print(val * c)
	t = t - 1


def solve():
	(b, p, f) = [int(x) for x in input().split(' ')]
	(h, c) = [int(x) for x in input().split(' ')]
	ans = 0
	max_burger = int(b // 2)
	if h > c:
		if p > int(b // 2):
			ans += h * int(b // 2)
			b = 0
		else:
			ans += h * p
			b -= p * 2
		if b != 0:
			if f > int(b // 2):
				ans += c * int(b // 2)
				b = 0
			else:
				ans += c * f
				b -= f * 2
	else:
		if f > int(b // 2):
			ans += c * int(b // 2)
			b = 0
		else:
			ans += c * f
			b -= f * 2
		if b != 0:
			if p > int(b // 2):
				ans += h * int(b // 2)
				b = 0
			else:
				ans += h * p
				b -= c * 2
	return ans
t = int(input())
for i in range(t):
	ans = solve()
	print(ans)


def solve(b, p, f, h, c):
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	total = 0
	total += h * min(b // 2, p)
	remains = b - 2 * min(b // 2, p)
	total += c * min(remains // 2, f)
	return total

def main():
	for _ in range(int(input().strip())):
		(b, p, f) = map(int, input().strip().split())
		(h, c) = map(int, input().strip().split())
		result = solve(b, p, f, h, c)
		print(result)
main()


t = int(input())
for t in range(t):
	profit = 0
	ings = [int(e) for e in input().split()]
	prices = [int(e) for e in input().split()]
	buns = ings[0]
	ham = ings[1]
	chi = ings[2]
	h = prices[0]
	c = prices[1]
	buns -= buns % 2
	buns /= 2
	if h >= c:
		smol = min(buns, ham)
		buns -= smol
		profit += smol * h
		if buns > 0 and chi > 0:
			smol = min(buns, chi)
			buns -= smol
			profit += smol * c
	elif c > h:
		smol = min(buns, chi)
		buns -= smol
		profit += smol * c
		if buns > 0 and ham > 0:
			smol = min(buns, ham)
			buns -= smol
			profit += smol * h
	print(int(profit))


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	nh = nc = 0
	if f * 2 <= b:
		nc = f
		b -= f * 2
		if p * 2 <= b:
			nh = p
		else:
			nh = b // 2
	elif b >= 2:
		nc = b // 2
		b -= nc * 2
	res = nh * h + nc * c
	print(res)


test_cases = int(input())
for i in range(test_cases):
	(b, p, c) = map(int, input().split())
	(hp, cp) = map(int, input().split())
	Total_burgers = b // 2
	better_price = max(hp, cp)
	worse_price = min(hp, cp)
	if better_price == hp:
		better_qty = p if Total_burgers - p >= 0 else Total_burgers
		worse_qty = c if Total_burgers - better_qty >= c else Total_burgers - better_qty
	else:
		better_qty = c if Total_burgers - c >= 0 else Total_burgers
		worse_qty = Total_burgers - min(better_qty, p)
		worse_qty = p if Total_burgers - better_qty >= p else Total_burgers - better_qty
	amt = better_price * better_qty + worse_price * worse_qty
	print(amt)


for t in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	m = 0
	n = 0
	if c >= h:
		if b // 2 >= f:
			m = f
			b = b - 2 * f
			if b // 2 >= p:
				n = p
			else:
				n = b // 2
		else:
			m = b // 2
	elif b // 2 >= p:
		n = p
		b = b - 2 * p
		if b // 2 >= f:
			m = f
		else:
			m = b // 2
	else:
		n = b // 2
	d = m * c + n * h
	print(d)


for i in range(int(input())):
	(a, d, w) = ([int(i) for i in input().split()], [int(i) for i in input().split()], 0)
	a[0] = int(a[0] / 2)
	(w, a[0]) = (max(d) * min(a[d.index(max(d)) + 1], a[0]), max(0, a[0] - a[d.index(max(d)) + 1]))
	w += min(d) * min(a[d.index(min(d)) + 1], a[0])
	print(w)


for i in range(int(input())):
	(kbread, kgamb, kchic) = map(int, input().split())
	(costg, costch) = map(int, input().split())
	res = 0
	if costg >= costch:
		res += min(kbread // 2, kgamb) * costg
		kbread -= res // costg * 2
		res += min(kbread // 2, kchic) * costch
	else:
		res += min(kbread // 2, kchic) * costch
		kbread -= res // costch * 2
		res += min(kbread // 2, kgamb) * costg
	print(res)


from sys import stdin, stdout
from collections import defaultdict
import math
import copy
T = int(input())
for i in range(T):
	(B, P, F) = [int(x) for x in stdin.readline().split()]
	(H, C) = [int(x) for x in stdin.readline().split()]
	X = B // 2
	profit = 0
	if H >= C:
		m = min(P, X)
		profit += m * H
		X -= m
		m = min(F, X)
		if m < 0:
			m = 0
		profit += m * C
	elif H < C:
		m = min(F, X)
		profit += m * C
		X -= m
		m = min(P, X)
		if m < 0:
			m = 0
		profit += m * H
	print(profit)


n = int(input())
for el in range(n):
	total = 0
	a = list(map(int, input().split()))
	bread = a[0] // 2
	b = list(map(int, input().split()))
	if b[0] > b[1]:
		if bread >= a[1]:
			total += a[1] * b[0]
			bread -= a[1]
			if bread >= a[2]:
				total += a[2] * b[1]
			else:
				total += bread * b[1]
		else:
			total += bread * b[0]
	elif bread >= a[2]:
		total += a[2] * b[1]
		bread -= a[2]
		if bread >= a[1]:
			total += a[1] * b[0]
		else:
			total += bread * b[0]
	else:
		total += bread * b[1]
	print(total)


q = int(input())
for i in range(q):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if b == 1:
		print(0)
	else:
		sum = 0
		a = b // 2
		if h > c:
			if p > a:
				sum = h * a
			elif a > p + f:
				sum = p * h + f * c
			else:
				sum = max([p * h + (a - p) * c, f * c + (a - f) * h])
		elif f > a:
			sum = c * a
		elif a > p + f:
			sum = p * h + f * c
		else:
			sum = max([p * h + (a - p) * c, f * c + (a - f) * h])
		print(sum)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	(p1, p2) = map(int, input().split())
	sum1 = 0
	if n < 2:
		print('0')
	else:
		if p1 > p2:
			while n > 1:
				if m > 0:
					m = m - 1
					sum1 = sum1 + p1
				elif k > 0:
					k = k - 1
					sum1 = sum1 + p2
				n = n - 2
		else:
			while n > 1:
				if k > 0:
					k = k - 1
					sum1 = sum1 + p2
				elif m > 0:
					m = m - 1
					sum1 = sum1 + p1
				n = n - 2
		print(sum1)


t = int(input())
for x in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	money = 0
	if h > c:
		while b >= 2 and p >= 1:
			money += h
			b -= 2
			p -= 1
		while b >= 2 and f >= 1:
			money += c
			b -= 2
			f -= 1
	else:
		while b >= 2 and f >= 1:
			money += c
			b -= 2
			f -= 1
		while b >= 2 and p >= 1:
			money += h
			b -= 2
			p -= 1
	print(money)


t = int(input())
for _ in range(t):
	(bun, cow, chicken) = map(int, input().strip().split())
	(h, c) = map(int, input().strip().split())
	bun = bun // 2
	money = 0
	cost = 0
	a = bun
	b = bun
	m = min(a, cow)
	if m == a:
		money = money + m * h
	else:
		a = a - m
		money = money + m * h
		a = min(a, chicken)
		money = money + a * c
	n = min(b, chicken)
	if n == b:
		cost = cost + n * c
	else:
		b = b - n
		cost = cost + n * c
		b = min(b, cow)
		cost = cost + b * h
	print(max(cost, money))


def func(b, p, f, h, c):
	if b < 2:
		return 0
	b //= 2
	if h > c:
		max_price = h
		max_b = p
		min_price = c
		min_b = f
	else:
		max_price = c
		max_b = f
		min_price = h
		min_b = p
	if b > max_b:
		profit = max_b * max_price
		b -= max_b
		if b > min_b:
			profit += min_b * min_price
		else:
			profit += b * min_price
	else:
		profit = b * max_price
	return profit
num = int(input())
for i in range(num):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = func(b, p, f, h, c)
	print(profit)


t = int(input())
for _ in range(t):
	ans = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h <= c:
		while True:
			if b >= 2 and f >= 1:
				ans += c
				b -= 2
				f -= 1
			else:
				break
	if h < c:
		while True:
			if b >= 2 and p >= 1:
				ans += h
				b -= 2
				p -= 1
			else:
				break
	while True:
		if b >= 2 and p >= 1:
			ans += h
			b -= 2
			p -= 1
		else:
			break
	while True:
		if b >= 2 and f >= 1:
			ans += c
			b -= 2
			f -= 1
		else:
			break
	print(ans)


def main(b, p, f, h, c):
	a = b // 2
	if a <= p:
		return a * h
	elif p < a < p + f:
		return p * h + (a - p) * c
	else:
		return p * h + f * c
n = eval(input())
for i in range(n):
	(b, p, f) = tuple(map(eval, input().split()))
	(h, c) = tuple(map(eval, input().split()))
	if h >= c:
		print(main(b, p, f, h, c))
	else:
		print(main(b, f, p, c, h))


t = int(input())
v = []
for i in range(t):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(b, p, f) = (l1[0], l1[1], l1[2])
	(h, c) = (l2[0], l2[1])
	if c > h:
		c1 = min(b // 2, f)
		h1 = min((b - c1 * 2) // 2, p)
	else:
		h1 = min(b // 2, p)
		c1 = min((b - h1 * 2) // 2, f)
	m = c1 * c + h1 * h
	v.append(m)
for i in range(t):
	print(v[i])


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pro = 0
	rem = b
	if h >= c:
		if rem >= 2 * p:
			pro += p * h
			rem = rem - 2 * p
		else:
			pro += rem // 2 * h
			rem = 0
		if rem > 0:
			if rem >= 2 * f:
				pro += f * c
			else:
				pro += rem // 2 * c
	else:
		if rem >= 2 * f:
			pro += f * c
			rem = rem - 2 * f
		else:
			pro += rem // 2 * c
			rem = 0
		if rem > 0:
			if rem >= 2 * p:
				pro += p * h
			else:
				pro += rem // 2 * h
				rem = 0
	print(pro)


t = int(input())
for _ in range(t):
	ans = 0
	mat = list(map(int, input().split()))
	prices = list(map(int, input().split()))
	max_ind = prices.index(max(prices))
	if max_ind == 1:
		i = 2
	else:
		i = 1
	if mat[0] > 1:
		ans += min(mat[i], mat[0] // 2) * prices[max_ind]
		mat[0] -= min(mat[i], mat[0] // 2) * 2
		if mat[0] > 1:
			if i == 2:
				i = 1
			else:
				i = 2
			ans += min(mat[i], mat[0] // 2) * prices[max_ind - 1]
			mat[0] -= mat[i] * 2
		print(ans)
	else:
		print(0)


n = int(input())
for i in range(n):
	(nb, nf, nc) = map(int, input().split())
	(ph, pc) = map(int, input().split())
	to = 0
	if pc > ph:
		for i in range(nc):
			if nb >= 2:
				to += pc
				nb -= 2
			else:
				break
		for j in range(nf):
			if nb >= 2:
				to += ph
				nb -= 2
			else:
				break
	else:
		for i in range(nf):
			if nb >= 2:
				to += ph
				nb -= 2
			else:
				break
		for j in range(nc):
			if nb >= 2:
				to += pc
				nb -= 2
			else:
				break
	print(to)


kol = int(input())
for _ in range(kol):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	s = 0
	if b % 2 != 0:
		b -= 1
	b = b // 2
	if max(h, c) == h:
		s += min(b, p) * h
		(b, p) = (b - min(b, p), p - min(b, p))
		s += min(b, f) * c
	else:
		s += min(b, f) * c
		b -= min(b, f)
		s += min(b, p) * h
	print(s)


def main():
	for _ in range(int(input())):
		(bun, beef, chicken) = map(int, input().split())
		(hamb, chickb) = map(int, input().split())
		bun = bun // 2
		if hamb >= chickb:
			ans = min(bun, beef) * hamb
			bun -= min(bun, beef)
			ans += min(bun, chicken) * chickb
		else:
			ans = min(bun, chicken) * chickb
			bun -= min(bun, chicken)
			ans += min(bun, beef) * hamb
		print(ans)
main()


t = int(input())
i = 0
for i in range(0, t):
	(x, y, z) = map(int, input().split())
	(x1, x2) = map(int, input().split())

	def maxvalue(x, y, z, x1, y1):
		totalburger = x // 2
		if y + z >= totalburger:
			if x1 > x2:
				chickenburger = totalburger - y
				if chickenburger > 0:
					a = x1 * y + chickenburger * x2
				else:
					a = totalburger * x1
			else:
				beefburger = totalburger - z
				if beefburger > 0:
					a = z * x2 + beefburger * x1
				else:
					a = totalburger * x2
		else:
			a = y * x1 + z * x2
		print(a)
	maxvalue(x, y, z, x1, x2)


def burgers(tc):
	res = []
	while tc > 0:
		profit = 0
		(b, p, f) = list(map(int, input().strip().split()))
		(h, c) = list(map(int, input().strip().split()))
		while True:
			if b < 2:
				break
			if h == c:
				while b > 1 and p > 0:
					b -= 2
					p -= 1
					profit += h
				while b > 1 and f > 0:
					b -= 2
					f -= 1
					profit += h
				break
			if h > c:
				while b > 1 and p > 0:
					b -= 2
					p -= 1
					profit += h
				while b > 1 and f > 0:
					b -= 2
					f -= 1
					profit += c
				break
			if c > h:
				while b > 1 and f > 0:
					b -= 2
					f -= 1
					profit += c
				while b > 1 and p > 0:
					b -= 2
					p -= 1
					profit += h
				break
		res.append(profit)
		tc -= 1
	for q in res:
		print(q)
t = int(input())
burgers(t)


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if c >= h:
		more = [f, c]
		less = [p, h]
	else:
		more = [p, h]
		less = [f, c]
	total = 0
	if b - more[0] >= 0:
		total += more[0] * more[1]
		b -= more[0]
	else:
		total += more[1] * b
		b = 0
	if b - less[0] >= 0:
		total += less[0] * less[1]
	else:
		total += less[1] * b
	print(total)


for t in range(int(input())):
	(b, p, f) = [int(j) for j in input().split()]
	(h, c) = [int(j) for j in input().split()]
	ans = 0
	if c > h:
		(p, f) = (f, p)
		(h, c) = (c, h)
	if h >= c:
		if 2 * p <= b:
			ans = p * h
			b = b - 2 * p
			if b > 1:
				if 2 * f <= b:
					ans += f * c
				else:
					ans += b // 2 * c
		else:
			ans = b // 2 * h
			b = 0
	print(ans)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	a = [p, f]
	prc = list(map(int, input().split()))
	i = prc.index(max(prc))
	b >>= 1
	pro = prc[i] * min(b, a[i])
	b -= min(b, a[i])
	pro += prc[not i] * min(b, a[not i])
	print(pro)


t = int(input())
for i in range(t):
	(a, b, c) = list(map(int, input().strip().split()))
	(d, e) = list(map(int, input().strip().split()))
	if d > e:
		g = min(b, a // 2)
		a = a - g * 2
		h = min(c, a // 2)
		print(g * d + h * e)
	elif d < e:
		g = min(c, a // 2)
		a = a - g * 2
		h = min(b, a // 2)
		print(g * e + h * d)
	else:
		print(min(b + c, a // 2) * d)


import math
t = int(input())
for t in range(t):
	(bun, hamburg, cutlet) = map(int, input().split())
	(hamburg_price, cutlet_price) = map(int, input().split())
	if bun < 2:
		print('0')
	elif cutlet_price > hamburg_price:
		if bun >= 2 * cutlet:
			cutlet_profit = cutlet * cutlet_price
			bun -= 2 * cutlet
			if bun >= 2 * hamburg:
				hamburg_profit = hamburg * hamburg_price
			else:
				hamburg_profit = math.floor(bun / 2) * hamburg_price
			print(cutlet_profit + hamburg_profit)
		else:
			cutlet_profit = math.floor(bun / 2) * cutlet_price
			print(cutlet_profit)
	elif bun >= 2 * hamburg:
		hamburg_profit = hamburg * hamburg_price
		bun -= 2 * hamburg
		if bun >= 2 * cutlet:
			cutlet_profit = cutlet * cutlet_price
		else:
			cutlet_profit = math.floor(bun / 2) * cutlet_price
		print(cutlet_profit + hamburg_profit)
	else:
		hamburg_profit = math.floor(bun / 2) * hamburg_price
		print(hamburg_profit)


a = int(input())
for i in range(a):
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	profit = 0
	while True:
		if b[0] >= 2 and (b[1] >= 1 or b[2] >= 1):
			if c[0] > c[1]:
				if b[1] > 0:
					profit = profit + c[0]
					b[0] = b[0] - 2
					b[1] = b[1] - 1
				else:
					profit = profit + c[1]
					b[0] = b[0] - 2
					b[2] = b[2] - 1
			elif b[2] > 0:
				profit = profit + c[1]
				b[0] = b[0] - 2
				b[2] = b[2] - 1
			else:
				profit = profit + c[0]
				b[0] = b[0] - 2
				b[1] = b[1] - 1
		else:
			break
	print(profit)


t = int(input())
tk = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	hp = 0
	hf = 0
	th = 0
	if h > c:
		for i in range(p):
			if b >= 2:
				b -= 2
				hp += h
		for i in range(f):
			if b >= 2:
				b -= 2
				hf += c
	else:
		for i in range(f):
			if b >= 2:
				b -= 2
				hf += c
		for i in range(p):
			if b >= 2:
				b -= 2
				hp += h
	th = hp + hf
	tk.append(th)
for i in tk:
	print(i)


def main():
	t = int(input())
	while t > 0:
		(b, p, f) = map(int, input().split(' '))
		(h, c) = map(int, input().split(' '))
		profit = 0
		if b > 1:
			if h > c:
				minimum = b // 2
				if minimum > p:
					minimum = p
				b -= minimum * 2
				profit += minimum * h
				minimum = b // 2
				if minimum > c and minimum != 0:
					minimum = c
				profit += minimum * c
			else:
				minimum = b // 2
				if minimum > f:
					minimum = f
				b -= minimum * 2
				profit += minimum * c
				minimum = b // 2
				if minimum > p and minimum != 0:
					minimum = p
				profit += minimum * h
		print(profit)
		t -= 1
main()


q = int(input())
for i in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b < 2:
		print(0)
	else:
		bun = b // 2
		ham = min(bun, p)
		bun -= ham
		chick = min(bun, f)
		c1 = h * ham + c * chick
		bun1 = b // 2
		chick1 = min(bun1, f)
		bun1 -= chick1
		ham1 = min(bun1, p)
		c2 = h * ham1 + c * chick1
		print(max(c1, c2))


from sys import stdin

def func(n):
	count = 0
	rem = 0
	while n > 0:
		if (n + rem) % 2 == 0:
			n = (n + rem) // 2
			count += n
			rem = 0
		else:
			n = (n + rem) // 2
			count += n
			rem = 1
	return count
for _ in range(int(stdin.readline())):
	(b, p, f) = map(int, stdin.readline().split())
	if b % 2 == 1:
		b -= 1
	(h, c) = map(int, stdin.readline().split())
	cost = 0
	if h >= c:
		if p >= b // 2:
			cost += b // 2 * h
		else:
			cost += p * h
			b -= 2 * p
			if b % 2 == 1:
				b -= 1
			if f >= b // 2:
				cost += b // 2 * c
			else:
				cost += f * c
	elif f >= b // 2:
		cost += b // 2 * c
	else:
		cost += f * c
		b -= 2 * f
		if b % 2 == 1:
			b -= 1
		if p >= b // 2:
			cost += b // 2 * h
		else:
			cost += p * h
	print(cost)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(b, p, f) = iia()
	(h, c) = iia()
	piece = b // 2
	if piece >= p + f:
		print(h * p + c * f)
	else:
		if h > c:
			res = 0
			for i in range(piece):
				if p > 0:
					p -= 1
					res += h
				elif f > 0:
					f -= 1
					res += c
				else:
					break
		else:
			res = 0
			for i in range(piece):
				if f > 0:
					f -= 1
					res += c
				elif p > 0:
					p -= 1
					res += h
				else:
					break
		print(res)


t = int(input())
res = []
for i in range(t):
	ans = 0
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	b //= 2
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	cnt = min(b, p)
	ans += cnt * h
	b -= cnt
	cnt = min(b, f)
	ans += cnt * c
	res.append(ans)
[print(i) for i in res]


test = int(input())
for cases in range(test):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if h > c:
		ans += h * min(b // 2, p)
		b -= 2 * min(b // 2, p)
		ans += c * min(b // 2, f)
		c -= 2 * min(b // 2, f)
	else:
		ans += c * min(b // 2, f)
		b -= 2 * min(b // 2, f)
		ans += h * min(b // 2, p)
		b -= 2 * min(b // 2, p)
	print(ans)


import math, sys
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
n = int(input())
for i in range(0, n):
	(b, p, f) = li()
	b = b // 2
	(h, c) = li()
	s = 0
	if h >= c:
		s = s + min(b, p) * h
		b = b - min(b, p)
		s = s + min(b, f) * c
		print(s)
	else:
		(h, c) = (c, h)
		(p, f) = (f, p)
		s = s + min(b, p) * h
		b = b - min(b, p)
		s = s + min(b, f) * c
		print(s)


for i in range(int(input())):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	roti = b // 2
	hasil = 0
	while roti > 0 and c > h:
		if f > 0:
			hasil += c
			roti -= 1
			f -= 1
		else:
			hasil += h
			roti -= 1
			p -= 1
		if f == 0 and p == 0:
			break
	while roti > 0 and h >= c:
		if p > 0:
			hasil += h
			roti -= 1
			p -= 1
		else:
			hasil += c
			roti -= 1
			f -= 1
		if f == 0 and p == 0:
			break
	print(hasil)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(b, p, f) = inar()
		(h, c) = inar()
		if h < c:
			(h, c) = (c, h)
			(p, f) = (f, p)
		take = min(p, b // 2)
		ans = take * h
		b -= take * 2
		take = min(f, b // 2)
		ans += take * c
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(buns, beef, chicken) = map(int, input().split())
	(hamburger, chicken_burger) = map(int, input().split())
	total = 0
	if buns < 2:
		pass
	elif hamburger > chicken_burger:
		if buns < 2 * beef:
			if buns % 2 == 0:
				total += int(buns / 2) * hamburger
			else:
				total += int((buns - 1) / 2) * hamburger
		else:
			total += hamburger * beef
			buns -= 2 * beef
			if buns < 2 * chicken:
				if buns % 2 == 0:
					total += int(buns / 2) * chicken_burger
				else:
					total += int((buns - 1) / 2) * chicken_burger
			else:
				total += chicken_burger * chicken
	elif buns < 2 * chicken:
		if buns % 2 == 0:
			total += int(buns / 2) * chicken_burger
		else:
			total += int((buns - 1) / 2) * chicken_burger
	else:
		total += chicken_burger * chicken
		buns -= 2 * chicken
		if buns < 2 * beef:
			if buns % 2 == 0:
				total += int(buns / 2) * hamburger
			else:
				total += int((buns - 1) / 2) * hamburger
		else:
			total += hamburger * beef
	print(total)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	an = 0
	if h > c:
		p = min(b // 2, p)
		b = b - 2 * p
		an = an + h * p
		if b > 1:
			q = min(b // 2, f)
			an = an + c * q
	else:
		f = min(b // 2, f)
		b = b - 2 * f
		an = an + c * f
		if b > 1:
			q = min(b // 2, p)
			an = an + h * q
	print(an)


def get_value(v):
	return [int(x) for x in v]
T = int(input())
while T != 0:
	T -= 1
	n = get_value(input().split())
	p = get_value(input().split())
	nn = n[0] // 2
	ans = 0
	if p[0] > p[1]:
		if n[1] <= nn:
			ans += p[0] * n[1]
			nn -= n[1]
			if n[2] <= nn:
				ans += p[1] * n[2]
				nn -= n[2]
			else:
				ans += p[1] * nn
		else:
			ans += p[0] * nn
	elif n[2] <= nn:
		ans += p[1] * n[2]
		nn -= n[2]
		if n[1] <= nn:
			ans += p[0] * n[1]
			nn -= n[1]
		else:
			ans += p[0] * nn
	else:
		ans += p[1] * nn
	print(ans)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
for _ in range(ri(1)):
	(b, p, f) = ri()
	(h, c) = ri()
	ans = 0
	if h < c:
		ans += c * min(f, b // 2)
		if b // 2 < f:
			take = b // 2 * 2
			b = b - take
		else:
			b = b - 2 * f
		ans += h * min(p, b // 2)
	else:
		ans += h * min(p, b // 2)
		if b // 2 < p:
			take = b // 2 * 2
			b = b - take
		else:
			b = b - 2 * p
		ans += c * min(f, b // 2)
	print(ans)


n = int(input())
for _ in range(n):
	(bun, beef, chicken) = input().split(' ')
	(beef_price, chicken_price) = input().split(' ')
	(bun, beef, chicken) = (int(bun), int(beef), int(chicken))
	(beef_price, chicken_price) = (int(beef_price), int(chicken_price))
	price = 0
	bun = bun // 2
	if bun == 0:
		print(price)
	elif beef_price <= chicken_price:
		min_count = min(bun, chicken)
		bun -= min_count
		price += min_count * chicken_price
		min_count = min(bun, beef)
		price += min_count * beef_price
		print(price)
	else:
		min_count = min(bun, beef)
		bun -= min_count
		price += min_count * beef_price
		min_count = min(bun, chicken)
		price += min_count * chicken_price
		print(price)


for i in range(int(input())):
	(b, p, f) = [int(elem) for elem in input().split()]
	(h, c) = [int(elem) for elem in input().split()]
	prise = 0
	b = b // 2
	if h > c:
		prise += h * min(b, p)
		b -= min(b, p)
		prise += c * min(b, f)
	else:
		prise += c * min(b, f)
		b -= min(b, f)
		prise += h * min(b, p)
	print(prise)


t = int(input())
while t > 0:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if h >= c:
		a = min(b, p)
		b = b - a
		r = a * h
		v = min(b, f)
		r = r + v * c
	else:
		cb = min(b, f)
		b = b - cb
		r = cb * c
		hb = min(b, p)
		r = r + hb * h
	print(r)
	t = t - 1


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	total = 0
	if c > h:
		make = min(f, b // 2)
		total += make * c
		b -= make * 2
		make = min(p, b // 2)
		total += make * h
	else:
		make = min(p, b // 2)
		total += make * h
		b -= make * 2
		make = min(f, b // 2)
		total += make * c
	print(total)


n = int(input())
for _ in range(n):
	arr = [int(num) for num in input().split()]
	arr1 = [int(num) for num in input().split()]
	if (arr[1] + arr[2]) * 2 <= arr[0]:
		print(arr[1] * arr1[0] + arr[2] * arr1[1])
	else:
		b = arr[0] // 2
		a = 0
		m = arr1.index(max(arr1))
		n = arr1.index(min(arr1))
		for _ in range(b):
			if arr[m + 1] > 0:
				a += arr1[m]
				arr[m + 1] -= 1
			else:
				a += arr1[n]
		print(a)


T_ON = 1
DEBUG_ON = 0
MOD = 998244353

def solve():
	(b, p, f) = read_ints()
	(h, c) = read_ints()
	profits = 0
	if h < c:
		a = min(f, b // 2)
		profits += a * c
		f -= a
		b -= 2 * a
		a = min(p, b // 2)
		profits += a * h
	else:
		a = min(p, b // 2)
		profits += a * h
		p -= a
		b -= 2 * a
		a = min(f, b // 2)
		profits += a * c
	print(profits)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


t = int(input())
for i in range(t):
	(x, y, z) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	if y + z <= x // 2:
		q = y * h + z * c
		print(q)
	elif c > h:
		if x // 2 >= z:
			r = z * c + (x // 2 - z) * h
			print(r)
		else:
			print(x // 2 * c)
	elif h > c:
		if x // 2 >= y:
			s = y * h + (x // 2 - y) * c
			print(s)
		else:
			print(x // 2 * h)
	elif h == c:
		print(x // 2 * h)


t = int(input())
for i in range(t):
	my = [int(x) for x in input().split()]
	b = my[0]
	p = my[1]
	f = my[2]
	cost = [int(x) for x in input().split()]
	h = cost[0]
	c = cost[1]
	sum = 0
	if b >= 2 * (p + f):
		sum = p * h + f * c
	elif b < 2:
		sum = 0
	elif h > c:
		b = b // 2
		if b >= p:
			sum = p * h
			sum = sum + (b - p) * c
		else:
			sum = b * h
	else:
		b = b // 2
		if b >= f:
			sum = f * c
			sum = sum + (b - f) * h
		else:
			sum = b * c
	print(sum)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	buns = a // 2
	if a <= 1:
		ans = 0
	elif b + c < buns:
		ans = b * x + c * y
	elif x > y:
		if b > buns:
			ans = x * buns
		else:
			ans = b * x + (buns - b) * y
	elif c > buns:
		ans = y * buns
	else:
		ans = c * y + (buns - c) * x
	print(ans)


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))
for i in range(I1()):
	(b, p, f) = I0()
	(h, c) = I0()
	if h >= c:
		res = min(b // 2, p)
		b -= min(res * 2, b)
		res1 = min(b // 2, f)
		print(res * h + res1 * c)
	else:
		res = min(b // 2, f)
		b -= min(res * 2, b)
		res1 = min(b // 2, p)
		print(res * c + res1 * h)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	if a < 2:
		print(0)
	elif int(a / 2) >= b + c:
		print(b * d + c * e)
	elif d >= e:
		if b <= a / 2:
			print(b * d + int(a / 2 - b) * e)
		else:
			print(int(a / 2) * d)
	elif c <= a / 2:
		print(c * e + int(a / 2 - c) * d)
	else:
		print(int(a / 2) * e)


try:
	for __ in range(int(input())):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		ans = 0
		if h > c:
			while b > 1 and p > 0:
				ans += h
				b -= 2
				p -= 1
			if b > 1:
				while b > 1 and f > 0:
					ans += c
					b -= 2
					f -= 1
		else:
			while b > 1 and f > 0:
				ans += c
				b -= 2
				f -= 1
			if b > 1:
				while b > 1 and p > 0:
					ans += h
					b -= 2
					p -= 1
		print(ans)
except:
	pass


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if c > h:
		(p, f) = (f, p)
		(c, h) = (h, c)
	bb = min(b // 2, p)
	cb = min(b // 2, p + f) - bb
	print(bb * h + cb * c)


import sys
input = sys.stdin.readline
for i in range(int(input())):
	b = list(map(int, input().split()))
	(m, n) = map(int, input().split())
	c = b[0]
	d = b[1]
	e = b[2]
	p = 0
	q = 0
	if m > n:
		p = min(c // 2, d)
		c += -2 * p
		if c > 1:
			q = min(c // 2, e)
		print(m * p + n * q)
	else:
		q = min(c // 2, e)
		c += -2 * q
		if c > 1:
			p = min(c // 2, d)
		r = m * p + n * q
		print(r)


t = int(input())
for case in range(t):
	(b, p, f) = [int(s) for s in input().split(' ')]
	(h, c) = [int(s) for s in input().split(' ')]
	if h > c:
		x = min(b // 2, p)
		y = x * h
		b -= 2 * x
		y += min(b // 2, f) * c
	else:
		x = min(b // 2, f)
		y = x * c
		b -= 2 * x
		y += min(b // 2, p) * h
	print(y)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	bread = b // 2
	ans_one = h * min(bread, p) + c * min(f, max(0, bread - p))
	ans_two = c * min(bread, f) + h * min(p, max(0, bread - f))
	res = max(ans_one, ans_two)
	print(res)


import sys
in_file = sys.stdin
t = int(in_file.readline().strip())
for _ in range(t):
	(b, p, f) = map(int, in_file.readline().strip().split())
	(h, c) = map(int, in_file.readline().strip().split())
	r = 0
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	r += h * min(p, b // 2)
	b -= 2 * min(p, b // 2)
	r += c * min(f, b // 2)
	sys.stdout.write(str(r) + '\n')
sys.stdout.flush()


import sys
from statistics import mean
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	(b, p, f) = invr()
	(h, c) = invr()
	money = 0
	if h > c:
		if p * 2 <= b:
			b = b - p * 2
			money = money + h * p
			if f * 2 <= b:
				b = b - f * 2
				money = money + c * f
			else:
				x = int(b / 2)
				money = money + c * x
		else:
			x = int(b / 2)
			money = money + x * h
	elif f * 2 <= b:
		b = b - f * 2
		money = money + c * f
		if p * 2 <= b:
			b = b - p * 2
			money = money + h * p
		else:
			x = int(b / 2)
			money = money + h * x
	else:
		x = int(b / 2)
		money = money + x * c
	print(money)


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(b, f, c) = map(int, input().split())
	(h, cc) = map(int, input().split())
	r = 0
	if h >= cc:
		re = min(b // 2, f)
		b -= re * 2
		r += h * re
		re = min(b // 2, c)
		b -= re * 2
		r += cc * re
	else:
		re = min(b // 2, c)
		b -= re * 2
		r += cc * re
		re = min(b // 2, f)
		b -= re * 2
		r += h * re
	print(r)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	n = b // 2
	res = 0
	for i in range(min(n, p) + 1):
		j = min(n - i, f)
		res = max(res, h * i + c * j)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	sum = 0
	if p + f > b // 2:
		if h > c:
			if p * 2 < b:
				b -= 2 * p
				sum += h * p + b // 2 * c
				print(sum)
			else:
				print(b // 2 * h)
		elif f * 2 < b:
			b -= 2 * f
			sum += c * f + b // 2 * h
			print(sum)
		else:
			print(b // 2 * c)
	else:
		print(h * p + f * c)


def do():
	n = int(input())
	t = []
	for _ in range(n):
		(b, p, f) = map(int, input().split(' '))
		(h, c) = map(int, input().split(' '))
		res = 0
		if h > c:
			hs = min(b // 2, p)
			cs = min((b - hs * 2) // 2, f)
		else:
			cs = min(b // 2, f)
			hs = min((b - cs * 2) // 2, p)
		res += h * hs
		res += c * cs
		t.append(res)
	for _ in t:
		print(_)
do()


for _ in range(int(input().strip())):
	(b, p, f) = [int(i) for i in input().strip().split(' ')]
	(h, c) = [int(i) for i in input().strip().split(' ')]
	if h >= c:
		hmade = min(b // 2, p)
		pr = hmade * h
		b -= hmade * 2
		cmade = min(b // 2, f)
		pr += cmade * c
	else:
		cmade = min(b // 2, f)
		pr = cmade * c
		b -= cmade * 2
		hmade = min(b // 2, p)
		pr += hmade * h
	print(pr)


t = int(input())
for i in range(t):
	cost = 0
	s1 = [int(x) for x in input().split()]
	s2 = [int(x) for x in input().split()]
	b = s1[0]
	p = s1[1]
	f = s1[2]
	h = s2[0]
	c = s2[1]
	d = b // 2
	if h > c:
		if p < d:
			cost += p * h
			ost = d - p
			if f >= ost and ost != 0:
				cost += (d - p) * c
			else:
				cost += f * c
		else:
			cost += d * h
	elif f < d:
		cost += f * c
		ost = d - f
		if ost != 0 and p >= ost:
			cost += (d - f) * h
		else:
			cost += p * h
	else:
		cost += d * c
	print(cost)


def naiveSolve():
	return

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(b, p, f) = readIntArr()
		(h, c) = readIntArr()
		best = 0
		for pp in range(p + 1):
			b2 = b - 2 * pp
			if b2 < 0:
				break
			best = max(best, h * pp + c * min(b2 // 2, f))
		allans.append(best)
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
from math import gcd, floor, ceil
for _abc in range(1):
	main()


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if h > c:
		ans += h * min(b // 2, p)
		b -= min(b // 2, p) * 2
		ans += c * min(b // 2, f)
	else:
		ans += c * min(b // 2, f)
		b -= min(b // 2, f) * 2
		ans += h * min(b // 2, p)
	print(ans)


t = int(input())
for _ in range(t):
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	(b, p, f) = (s1[0], s1[1], s1[2])
	(h, c) = (s2[0], s2[1])
	if h > c:
		if 2 * p >= b:
			print(b // 2 * h)
		else:
			sum = p * h
			if b - 2 * p - 2 * f >= 0:
				sum = sum + f * c
			else:
				sum = sum + (b - 2 * p) // 2 * c
			print(sum)
	elif 2 * f >= b:
		print(b // 2 * c)
	else:
		sum = f * c
		if b - 2 * f - 2 * p >= 0:
			sum = sum + p * h
		else:
			sum = sum + (b - 2 * f) // 2 * h
		print(sum)


import math
n = input()
for i in range(int(n)):
	bal = input()
	ball = input()
	lst = bal.split()
	bun = int(lst[0])
	beef = int(lst[1])
	chicken = int(lst[2])
	lis = ball.split()
	hum = int(lis[0])
	chik = int(lis[1])
	ans = 0
	if hum > chik:
		if bun > beef * 2:
			ans = ans + hum * beef
			bun = bun - beef * 2
		else:
			ans = ans + (bun - bun % 2) / 2 * hum
			bun = 0
		ans = ans + min(chicken * 2, bun - bun % 2) / 2 * chik
	else:
		if bun > chicken * 2:
			ans = ans + chik * chicken
			bun = bun - chicken * 2
		else:
			ans = ans + (bun - bun % 2) / 2 * chik
			bun = 0
		ans = ans + min(beef * 2, bun - bun % 2) / 2 * hum
	print(math.ceil(ans))


A = []
for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(pr1, pr2) = map(int, input().split())
	if pr1 < pr2:
		(pr1, pr2) = (pr2, pr1)
		(b, c) = (c, b)
	x = 0
	if a // 2 >= b:
		a -= b * 2
		x += pr1 * b
		if a // 2 >= c:
			x += pr2 * c
		else:
			x += a // 2 * pr2
	else:
		x += a // 2 * pr1
	A.append(x)
for a in A:
	print(a)


n = int(input())
for a in range(n):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if b < 2:
		print(0)
		continue
	b = b // 2
	profit = 0
	mp = max(h, c)
	if mp == h:
		(p1, p2) = (p, f)
		(c1, c2) = (h, c)
	else:
		(p1, p2) = (f, p)
		(c1, c2) = (c, h)
	if b <= p1:
		profit += b * c1
		print(profit)
		continue
	else:
		profit += p1 * c1
		if b - p1 > p2:
			profit += p2 * c2
		else:
			profit += (b - p1) * c2
		print(profit)


test_cases = int(input())
for i in range(test_cases):
	(buns, hamburger, chicken_burger) = map(int, input().split(' '))
	(hamburger_cost, chicken_burger_cost) = map(int, input().split(' '))
	burger_cost = {hamburger_cost: hamburger, chicken_burger_cost: chicken_burger}
	(first_burger, second_burger) = (max(hamburger_cost, chicken_burger_cost), min(hamburger_cost, chicken_burger_cost))
	buy = min(buns // 2, burger_cost[first_burger])
	first_bill = buy * first_burger
	buns = buns - buy * 2
	second_bill = min(buns // 2, burger_cost[second_burger]) * second_burger
	print(first_bill + second_bill)


q = int(input())
for ter in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	wyn = 0
	if h > c:
		while b > 0 and p > 0:
			b -= 1
			p -= 1
			wyn += h
		while b > 0 and f > 0:
			b -= 1
			f -= 1
			wyn += c
	else:
		while b > 0 and f > 0:
			b -= 1
			f -= 1
			wyn += c
		while b > 0 and p > 0:
			b -= 1
			p -= 1
			wyn += h
	print(wyn)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if p >= b:
		mah = h * b
	else:
		mah = h * p + c * min(f, b - p)
	if f >= b:
		mac = c * b
	else:
		mac = c * f + h * min(b - f, p)
	print(max(mac, mah))


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pro = 0
	if max(h, c) == c:
		m = f
		n = p
	if max(h, c) == h:
		m = p
		n = f
	if b >= 2:
		while b >= 2 and m > 0:
			b = b - 2
			m = m - 1
			pro += max(h, c)
		while b >= 2 and n > 0:
			b = b - 2
			n = n - 1
			pro += min(h, c)
		print(pro)
	else:
		print(0)


def main():
	(a, b, c) = map(int, input().split())
	(n, m) = map(int, input().split())
	count = 0
	if n > m:
		while b > 0 and a > 1:
			b -= 1
			a -= 2
			count += n
		while c > 0 and a > 1:
			c -= 1
			a -= 2
			count += m
	else:
		while c > 0 and a > 1:
			c -= 1
			a -= 2
			count += m
		while b > 0 and a > 1:
			b -= 1
			a -= 2
			count += n
	return count
t = int(input())
for i in range(t):
	print(main())


def calculate_remaining_buns(b, n):
	return b - 2 * n if b - 2 * n >= 0 else 0

def max_profit(b, p, f, h, c):
	buns = b
	profit = 0
	if h > c:
		buns = calculate_remaining_buns(b, p)
		if buns > 0:
			profit = p * h
			remaining_buns = calculate_remaining_buns(buns, f)
			if remaining_buns > 0:
				profit += f * c
			else:
				profit += buns // 2 * c
		else:
			profit = b // 2 * h
	else:
		buns = calculate_remaining_buns(b, f)
		if buns > 0:
			profit = f * c
			remaining_buns = calculate_remaining_buns(buns, p)
			if remaining_buns > 0:
				profit += p * h
			else:
				profit += buns // 2 * h
		else:
			profit = b // 2 * c
	return profit
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(max_profit(b, p, f, h, c))


def calculate_salary(ingridients, costs):
	(b, p, f) = ingridients
	(ham_cost, chicken_cost) = costs
	burger_numbers = b // 2
	if burger_numbers == 0:
		return 0
	if chicken_cost > ham_cost:
		num_chicken = min(burger_numbers, f)
		num_ham = min(burger_numbers - num_chicken, p)
	else:
		num_ham = min(burger_numbers, p)
		num_chicken = min(burger_numbers - num_ham, f)
	return num_ham * ham_cost + num_chicken * chicken_cost
n = int(input())
for i in range(n):
	ingridients = map(int, input().rstrip().split())
	burger_numbers = map(int, input().rstrip().split())
	print(calculate_salary(ingridients, burger_numbers))


n = eval(input())
for i in range(n):
	s = input().split()
	b = int(eval(s[0]) / 2)
	p = eval(s[1])
	f = eval(s[2])
	s = input().split()
	h = eval(s[0])
	c = eval(s[1])
	if h > c:
		n1 = min(b, p)
		n2 = min(b - n1, f)
	else:
		n2 = min(b, f)
		n1 = min(b - n2, p)
	ans = int(n1 * h + n2 * c)
	print(ans)


list = []
l = []
sum = 0
map = dict()
q = input()
q = int(q)
for i in range(q):
	map.clear()
	sum = 0
	list = input()
	list = list.split()
	for j in range(3):
		list[j] = int(list[j])
	l = input()
	l = l.split()
	for index in range(2):
		l[index] = int(l[index])
	buns = list[0]
	beef = list[1]
	chicken = list[2]
	hamPrice = l[0]
	chickPrice = l[1]
	map[1] = hamPrice
	map[2] = chickPrice
	maximum = max(map, key=map.get)
	minimum = min(map, key=map.get)
	if maximum == 1:
		fst = beef
		sec = chicken
	else:
		fst = chicken
		sec = beef
	while buns - fst * 2 < 0:
		fst -= 1
	if fst > 0:
		buns = buns - fst * 2
		sum += fst * map[maximum]
	while buns - sec * 2 < 0:
		sec -= 1
	if sec > 0:
		sum += sec * map[minimum]
	print(sum)


q = int(input())
for _ in range(q):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	a = 0
	if h > c:
		maxpr = h
		if p * 2 == b:
			a += p * h
		elif p * 2 > b:
			a += b // 2 * h
		else:
			b = b - 2 * p
			a += p * h + min(2 * f, b) // 2 * c
	else:
		maxpr = c
		if f * 2 == b:
			a += f * c
		elif f * 2 > b:
			a += b // 2 * c
		else:
			b = b - 2 * f
			a += f * c + min(2 * p, b) // 2 * h
	print(a)


q = int(input())
sol = []
for i in range(q):
	first_line = input().split(' ')
	b = int(first_line[0])
	p = int(first_line[1])
	f = int(first_line[2])
	second_line = input().split(' ')
	h = int(second_line[0])
	c = int(second_line[1])
	b = b // 2
	if c > h:
		(p, f) = (f, p)
		(h, c) = (c, h)
	p = p if b >= p else b
	b = b - p if b - p > 0 else 0
	f = f if b >= f else b
	res = h * p + c * f
	sol.append(res)
for i in range(len(sol)):
	print(sol[i])


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	arr = [c] * f + [h] * p
	arr = sorted(arr)
	pr = 0
	i = 0
	while b > 1 and arr:
		pr += arr.pop()
		b -= 2
	print(pr)


t = int(input())
for nt in range(t):
	(b, p, f) = [int(k) for k in input().split(' ')]
	(h, c) = [int(k) for k in input().split(' ')]
	if c > h:
		(c, h) = (h, c)
		(p, f) = (f, p)
	res = 0
	nbmx = min(b // 2, p)
	b -= nbmx * 2
	nbmn = min(b // 2, f)
	res = nbmx * h + nbmn * c
	print(res)


t = int(input())
while t:
	t -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	if h > c:
		temp = p * 2
		if temp > b:
			res = h * (b // 2)
			print(res)
			continue
		else:
			b = b - p * 2
			res += h * p
		temp = f * 2
		if temp > b:
			res += c * (b // 2)
			print(res)
			continue
		else:
			res += c * f
			print(res)
			continue
	else:
		temp = f * 2
		if temp > b:
			res += c * (b // 2)
			print(res)
			continue
		else:
			b = b - f * 2
			res += c * f
		temp = p * 2
		if temp > b:
			res += h * (b // 2)
			print(res)
			continue
		else:
			res += h * p
			print(res)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	(price1, price2, cnt1, cnt2) = (h, c, p, f) if h > c else (c, h, f, p)
	pairs = b // 2
	m = min(pairs, cnt1)
	pairs -= m
	profit += price1 * m
	m = min(pairs, cnt2)
	pairs -= m
	profit += price2 * m
	print(profit)


t = int(input())
while t > 0:
	t -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	num_of_bugs = b // 2
	if h > c:
		exp_price = h
		exp_item = p
		cheap_price = c
		cheap_item = f
	else:
		exp_price = c
		exp_item = f
		cheap_price = h
		cheap_item = p
	total = 0
	allowed_exp_item = exp_item if num_of_bugs >= exp_item else num_of_bugs
	num_of_bugs_left = num_of_bugs - allowed_exp_item
	allowed_cheap_item = num_of_bugs_left if num_of_bugs_left < cheap_item else cheap_item
	total = exp_price * allowed_exp_item + cheap_price * allowed_cheap_item
	arr = ['num_of_bugs', num_of_bugs, 'exp_price', exp_price, 'exp_item', exp_item, 'cheap_price', cheap_price, 'cheap_item', cheap_item, 'allowed_exp_item', allowed_exp_item, 'num_of_bugs_left', num_of_bugs_left, 'allowed_cheap_item', allowed_cheap_item, 'total', total]
	print(total)


num_q = int(input())
bfq = list()
hc = list()
for i in range(num_q * 2):
	row = list((int(i) for i in input().split(' ')))
	if i % 2 == 0:
		bfq.append(row)
	else:
		hc.append(row)
for i in range(len(bfq)):
	bepefs = bfq[i]
	b = bepefs[0] // 2
	p = bepefs[1]
	f = bepefs[2]
	ham_price = hc[i][0]
	chicken_price = hc[i][1]
	if b > p + f:
		total_profit = p * ham_price + f * chicken_price
		print(total_profit)
	elif b < p + f:
		if ham_price > chicken_price:
			if b - p > 0:
				total_profit = 0
				total_profit += ham_price * p + chicken_price * (b - p)
				print(total_profit)
			elif b - p < 0:
				total_profit = 0
				total_profit += ham_price * b
				print(total_profit)
			else:
				total_profit = ham_price * b
				print(total_profit)
		elif b - f > 0:
			total_profit = 0
			total_profit += chicken_price * f + ham_price * (b - f)
			print(total_profit)
		elif b - f < 0:
			total_profit = 0
			total_profit += chicken_price * b
			print(total_profit)
		else:
			total_profit = chicken_price * b
			print(total_profit)
	elif b == 0:
		print('b==0')
		print(0)
	elif b == p + f:
		if ham_price > chicken_price:
			total_profit = ham_price * p
			left = b - p
			if left > 0:
				total_profit += left * chicken_price
			print(total_profit)
		else:
			total_profit = chicken_price * f
			left - b - f
			if left > 0:
				total_profit += left * ham_price
			print(total_profit)


for t in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	(c1, c2) = [int(i) for i in input().split()]
	k = 0
	if c1 < c2:
		(c1, c2) = (c2, c1)
		(b, c) = (c, b)
	while a > 1 and b > 0:
		k += c1
		a -= 2
		b -= 1
	while a > 1 and c > 0:
		k += c2
		a -= 2
		c -= 1
	print(k)


for _ in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	a = b // 2
	if c >= h:
		d = a
		a = a - f
		if a <= 0:
			print(c * d)
		else:
			print(c * f + h * min(a, p))
	else:
		d = a
		a = a - p
		if a <= 0:
			print(h * d)
		else:
			print(h * p + c * min(a, f))


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(b, p, f) = map(int, input().split())
	n = b // 2
	(h, c) = map(int, input().split())
	if h >= c:
		if n <= p:
			print(h * n)
		elif n <= p + f:
			print(h * p + c * (n - p))
		else:
			print(h * p + c * f)
	elif n <= f:
		print(c * n)
	elif n <= f + p:
		print(h * (n - f) + c * f)
	else:
		print(h * p + c * f)


t = int(input())
for _ in range(t):
	l = list(map(int, input().strip().split()))
	b = l[0]
	p = l[1]
	f = l[2]
	l = list(map(int, input().strip().split()))
	h = l[0]
	c = l[1]
	if h > c:
		if int(b / 2) >= p:
			r = p * h
			b = int(b / 2) - p
			if b >= f:
				r = r + f * c
			else:
				r = r + b * c
		else:
			r = int(b / 2) * h
	elif int(b / 2) >= f:
		r = f * c
		b = int(b / 2) - f
		if b >= p:
			r = r + p * h
		else:
			r = r + b * h
	else:
		r = int(b / 2) * c
	print(int(r))


q = int(input())
for i in range(q):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	counter = 0
	k = b // 2
	arr = 0
	if h >= c:
		counter += min(k, p)
		k -= counter
		arr += counter * h
		counter = min(k, f)
		arr += counter * c
	else:
		counter += min(k, f)
		k -= counter
		arr += counter * c
		counter = min(k, p)
		arr += counter * h
	print(arr)


q = int(input())
for i in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		h_cnt = min(b // 2, p)
		b -= h_cnt * 2
		c_cnt = min(b // 2, f)
	else:
		c_cnt = min(b // 2, f)
		b -= c_cnt * 2
		h_cnt = min(b // 2, p)
	print(h_cnt * h + c_cnt * c)


class lanche:

	def __init__(self, qtd, preco):
		self.preco = preco
		self.qtd = qtd

	def __lt__(self, other):
		return self.preco < other.preco

	def __repr__(self):
		return '({}, {})'.format(self.preco, self.qtd)
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	ans = 0
	hamburger = lanche(p, h)
	frango = lanche(f, c)
	lista_lanches = [hamburger, frango]
	lista_lanches.sort(reverse=True)
	for l in lista_lanches:
		ans += min(l.qtd, b) * l.preco
		b -= min(l.qtd, b)
	print(ans)


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right
import math
for _ in range(int(input())):
	(b, p, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	if x < y:
		(x, y) = (y, x)
		(p, c) = (c, p)
	t = min(b, 2 * p)
	a = t // 2 * x
	b -= t
	q = min(b, 2 * c)
	a += q // 2 * y
	print(a)


a = int(input())
C = 0
h = 0
import math
for i in range(0, a):
	n = list(map(int, input().split()))
	p = list(map(int, input().split()))
	h = 0
	n[0] = math.floor(n[0] / 2)
	if p[0] < p[1]:
		c = p[0]
		p[0] = p[1]
		p[1] = c
		c = n[1]
		n[1] = n[2]
		n[2] = c
	if n[0] - n[1] >= 0:
		h = h + n[1] * p[0]
		n[0] = n[0] - n[1]
		if n[0] - n[2] >= 0:
			h = h + n[2] * p[1]
		else:
			h = h + n[0] * p[1]
	else:
		h = n[0] * p[0]
	print(h)


def calc_profit(b, p, f, p_price, f_price):
	b = int(b / 2)
	if f_price >= p_price:
		possible_f = min(b, f)
		possible_p = min(b - possible_f, p)
	else:
		possible_p = min(b, p)
		possible_f = min(b - possible_p, f)
	return possible_p * p_price + possible_f * f_price
n = int(input(''))
for i in range(0, n):
	(b, p, f) = [int(x) for x in str(input('')).split(' ')]
	(p_price, f_price) = [int(x) for x in str(input('')).split(' ')]
	print(calc_profit(b, p, f, p_price, f_price))


for _ in range(int(input())):
	(b, p, c) = map(int, input().split())
	(p1, p2) = map(int, input().split())
	maxx = 0
	if b // 2 <= p + c:
		for i in range(b // 2 + 1):
			if b // 2 - i <= p and i <= c:
				maxx = max(maxx, p1 * (b // 2 - i) + p2 * i)
	else:
		maxx = p1 * p + p2 * c
	print(maxx)


import sys
T = int(sys.stdin.readline())
for t in range(T):
	(b, p, f) = list(map(int, sys.stdin.readline().split()))
	(h, c) = list(map(int, sys.stdin.readline().split()))
	answer = 0
	if h >= c:
		if b >= 2 * p:
			answer = p * h + min((b - 2 * p) // 2, f) * c
		else:
			answer = b // 2 * h
	elif b >= 2 * f:
		answer = min((b - 2 * f) // 2, p) * h + f * c
	else:
		answer = b // 2 * c
	print(answer)


tests = int(input())
while tests != 0:
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	income = 0
	while b >= 2 and (p > 0 or f > 0):
		if h > c:
			if p > 0:
				income += h
				p -= 1
			else:
				income += c
				f -= 1
		elif f > 0:
			income += c
			f -= 1
		else:
			income += h
			p -= 1
		b -= 2
	print(income)
	tests -= 1


t = int(input())
kq = [0] * t
for i in range(0, t):
	a = input()
	a = a.split()
	for j in range(0, 3):
		a[j] = eval(a[j])
	b = input()
	b = b.split()
	for j in range(0, 2):
		b[j] = eval(b[j])
	if (a[1] + a[2]) * 2 <= a[0]:
		kq[i] = a[1] * b[0] + a[2] * b[1]
	if (a[1] + a[2]) * 2 > a[0]:
		if b[0] > b[1]:
			if a[0] >= 2 * a[1]:
				kq[i] = a[1] * b[0] + (a[0] - a[1] * 2) // 2 * b[1]
			if a[0] < 2 * a[1]:
				kq[i] = a[0] // 2 * b[0]
		elif b[0] < b[1]:
			if a[0] >= 2 * a[2]:
				kq[i] = a[2] * b[1] + (a[0] - 2 * a[2]) // 2 * b[0]
			elif a[0] < 2 * a[2]:
				kq[i] = a[0] // 2 * b[1]
		elif b[0] == b[1]:
			kq[i] = b[1] * (a[0] // 2)
for i in range(0, t):
	print(kq[i])


for rpt in range(int(input())):
	(buns, beef, chicken) = [int(x) for x in input().split(' ')]
	(beefprice, chickenprice) = [int(x) for x in input().split(' ')]
	maxburger = buns // 2
	if maxburger >= beef + chicken:
		print(beef * beefprice + chicken * chickenprice)
	elif beefprice > chickenprice:
		if maxburger > beef:
			print(beef * beefprice + (maxburger - beef) * chickenprice)
		else:
			print(maxburger * beefprice)
	elif maxburger > chicken:
		print((maxburger - chicken) * beefprice + chicken * chickenprice)
	else:
		print(maxburger * chickenprice)


def co(x, y):
	reqb = 2 * x + 2 * y
	reqc = x
	reqb1 = y
	if reqb <= b and reqc <= p and (reqb1 <= f):
		return h * x + c * y
	else:
		return 0
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	maxi = 0
	for i in range(101):
		for j in range(101):
			if co(i, j) > maxi:
				maxi = co(i, j)
	print(maxi)


def makeBurger(b, p, f, h, c):
	maxBurgers = int(b / 2)
	profit = 0
	if maxBurgers > p + f:
		maxBurgers = p + f
	if h > c:
		if maxBurgers > p:
			profit += p * h
			maxBurgers -= p
			if f > maxBurgers:
				profit += maxBurgers * c
			else:
				profit += f * c
		else:
			profit += maxBurgers * h
	elif maxBurgers > f:
		profit += f * c
		maxBurgers -= f
		if p > maxBurgers:
			profit += maxBurgers * h
		else:
			profit += p * h
	else:
		profit += maxBurgers * c
	print(profit)
t = int(input())
for i in range(t):
	(b, p, f) = input().split()
	(h, c) = input().split()
	(b, p, f, h, c) = (int(b), int(p), int(f), int(h), int(c))
	makeBurger(b, p, f, h, c)


t = int(input())
res_list = []
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	burger_count = b // 2
	if h >= c:
		if b // 2 > p:
			burger_count -= p
			res += h * p
			if burger_count <= f:
				res += burger_count * c
			else:
				res += f * c
		elif b // 2 < p:
			burger_count -= b // 2
			res += h * (b // 2)
		else:
			burger_count -= p
			res += h * p
	if c > h:
		if b // 2 > f:
			burger_count -= f
			res += c * f
			if burger_count <= p:
				res += burger_count * h
			else:
				res += p * h
		elif b // 2 < f:
			burger_count -= b // 2
			res += c * (b // 2)
		else:
			burger_count -= f
			res += c * f
	res_list.append(res)
for el in res_list:
	print(el)


t = int(input())
for i in range(1, t + 1):
	(b, p, f) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	(h, c) = input().split()
	h = int(h)
	c = int(c)
	b = int(b / 2)
	if b == 0:
		print('0')
	elif b > p + f:
		print(int(p * h + f * c))
	else:
		max1 = max(h, c)
		if h == max1:
			if b <= p:
				diff = p - b
				print((p - diff) * h)
			else:
				r1 = h * p
				b -= p
				r2 = b * c
				print(r1 + r2)
		elif b <= f:
			diff = f - b
			print((f - diff) * c)
		else:
			r1 = c * f
			b -= f
			r2 = b * h
			print(r1 + r2)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	ans = 0
	if p < f:
		for i in range(min(b, p) + 1):
			ans = max(ans, i * h + min(f, b - i) * c)
	else:
		for i in range(min(b, f) + 1):
			ans = max(ans, i * c + min(p, b - i) * h)
	print(ans)


T = int(input())
for kase in range(T):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if h > c:
		t = min(b // 2, p)
		ans = h * t + c * min((b - 2 * t) // 2, f)
	else:
		t = min(b // 2, f)
		ans = c * t + h * min((b - 2 * t) // 2, p)
	print(ans)


for _ in range(int(input())):
	(p, c, l) = list(map(int, input().split()))
	(b, s) = list(map(int, input().split()))
	bags = 0
	shoes = 0
	stop = False
	if b > s:
		while True:
			if p > 1 and c > 0:
				bags += 1
				p -= 2
				c -= 1
			elif p > 1 and l > 0:
				shoes += 1
				p -= 2
				l -= 1
			else:
				break
	else:
		while True:
			if p > 1 and l > 0:
				shoes += 1
				p -= 2
				l -= 1
			elif p > 1 and c > 0:
				bags += 1
				p -= 2
				c -= 1
			else:
				break
	print(bags * b + shoes * s)


def process(b, p, f, h, c):
	if b < 2:
		return 0
	if h >= c:
		t1 = min(p, b // 2)
		t2 = min((b - t1 * 2) // 2, f)
		return t1 * h + t2 * c
	else:
		t2 = min(f, b // 2)
		t1 = min((b - t2 * 2) // 2, p)
		return t1 * h + t2 * c
n = int(input())
for x in range(n):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	print(process(b, p, f, h, c))


ta = int(input())
for x in range(ta):
	(n, b, f) = map(int, input().split())
	l = list(map(int, input().split()))
	c = n // 2
	m1 = max(l)
	if m1 == l[0]:
		m11 = b
		m2 = l[1]
		m22 = f
	else:
		m11 = f
		m2 = l[0]
		m22 = b
	t = 0
	for i in range(c):
		if m11:
			t += m1
			m11 -= 1
		elif m22:
			t += m2
			m22 -= 1
		else:
			break
	print(t)


def getProfit(b, p, f, c1, c2):
	first = min(b // 2, p)
	b = b - 2 * first
	second = min(b // 2, f)
	return first * c1 + second * c2

def solve():
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	return getProfit(b, p, f, h, c)
t = int(input())
for _ in range(t):
	print(solve())


n = int(input())
for i in range(n):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(y) for y in input().split()]
	cnt = int()
	h_flag = int()
	c_flag = int()
	temp = b // 2
	if b == 1:
		print(0)
	else:
		if h == max(c, h):
			h_flag = 1
			while temp > 0 and p > 0:
				cnt += h
				p -= 1
				temp -= 1
		elif c == max(c, h):
			c_flag = 1
			while temp > 0 and f > 0:
				cnt += c
				f -= 1
				temp -= 1
		while temp > 0 and (p > 0 or f > 0):
			if p > 0:
				cnt += h
				p -= 1
				temp -= 1
			if f > 0:
				cnt += c
				f -= 1
				temp -= 1
		print(cnt)


for k in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	a = min(b // 2, p)
	bd = min(b // 2, f)
	print(max(a * h + min((b - 2 * a) // 2, f) * c, bd * c + min((b - 2 * bd) // 2, p) * h))


import math

def main():
	op = ''
	t = int(input())
	for i in range(t):
		(buns, beef, ck) = map(int, input().split(' '))
		(beef_price, ck_price) = map(int, input().split(' '))
		tot_profit = 0
		buns = math.floor(buns / 2)
		if beef_price >= ck_price:
			if buns >= beef:
				buns -= beef
				tot_profit += beef * beef_price
				tot_profit += ck_price * min(buns, ck)
			else:
				tot_profit += buns * beef_price
		elif buns >= ck:
			buns -= ck
			tot_profit += ck * ck_price
			tot_profit += beef_price * min(buns, beef)
		else:
			tot_profit += buns * ck_price
		op += str(tot_profit) + '\n'
	print(op)
main()


def solution(input):
	output = []
	for i in range(0, len(input)):
		(b, p, f, h, c) = input[i]
		flag = True
		profit = 0
		if h >= c:
			flag = True
		else:
			flag = False
		if flag == True:
			num = b // 2
			if num >= p:
				num = num - p
				profit = profit + h * p
				if num >= f:
					num = num - f
					profit = profit + f * c
				else:
					profit = profit + num * c
			else:
				profit = profit + h * num
		else:
			num = b // 2
			if num >= f:
				num = num - f
				profit = profit + c * f
				if num >= p:
					num = num - p
					profit = profit + p * h
				else:
					profit = profit + num * h
			else:
				profit = profit + c * num
		output.append(profit)
	return output

def main():
	inputData = []
	q = int(input())
	for i in range(0, q):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		inputData.append([b, p, f, h, c])
	result = solution(inputData)
	for i in range(0, len(result)):
		print(result[i])
main()


a = int(input())
g = 0
for i in range(a):
	b = input().split()
	c = input().split()
	v = int(b[0])
	if int(c[0]) > int(c[1]):
		g += min(int(b[1]), v // 2) * int(c[0])
		v -= g * 2 / int(c[0])
		g += min(int(b[2]), v // 2) * int(c[1])
	else:
		g += min(int(b[2]), v // 2) * int(c[1])
		v -= g * 2 / int(c[1])
		g += min(int(b[1]), v // 2) * int(c[0])
	print(int(g))
	g = 0


for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	if b == 0 or b == 1:
		print(0)
	else:
		amount = 0
		ham = 0
		chicken = 0
		if h > c:
			ham = min(p, b // 2)
			b = b - 2 * ham
			p = p - ham
			if b > 1:
				chicken = min(f, b // 2)
				f = f - chicken
				b = b - 2 * chicken
			amount = ham * h + chicken * c
			print(amount)
		else:
			chicken = min(f, b // 2)
			b = b - 2 * chicken
			f = f - chicken
			if b > 1:
				ham = min(p, b // 2)
				p = p - chicken
				b = b - 2 * chicken
			amount = ham * h + chicken * c
			print(amount)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b > (p + f) * 2:
		profit = h * p + c * f
		print(profit)
	elif b <= 1:
		print(0)
	else:
		if b % 2 != 0:
			b -= 1
		if c > h:
			while b < 2 * f:
				f -= 1
			income = c * f
			b = b - 2 * f
			income = income + h * (b // 2)
			print(income)
		else:
			while b < 2 * p:
				p -= 1
			inc = h * p
			b = b - 2 * p
			inc = inc + c * (b // 2)
			print(inc)


t = int(input())
otv = []
for i in range(0, t):
	ans = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b < 2:
		otv.append('0')
	elif h > c:
		if b >= p * 2:
			b -= p * 2
			ans += p * h
			k = b // 2
			ans += min(k, f) * c
		else:
			k = b // 2
			ans += k * h
		otv.append(str(ans))
	else:
		if b >= f * 2:
			b -= f * 2
			ans += f * c
			k = b // 2
			ans += min(k, p) * h
		else:
			k = b // 2
			ans += k * c
		otv.append(str(ans))
print('\n'.join(otv))


n = int(input())
for i in range(n):
	k = input()
	m = input()
	s = k.split()
	d = m.split()
	p = int(s[0])
	c = int(s[1])
	l = int(s[2])
	b = int(d[0])
	s = int(d[1])
	pro = 0
	p = int(p / 2)
	if s >= b:
		if p >= l:
			pro = pro + s * l
			p -= l
			l = 0
		else:
			pro += s * p
			p = 0
		if p >= c:
			pro = pro + c * b
			c = 0
			p = p - l
		else:
			pro += p * b
			p = 0
	else:
		if p >= c:
			pro = pro + c * b
			p = p - c
			c = 0
		else:
			pro += p * b
			p = 0
		if p >= l:
			pro = pro + s * l
			p -= l
			l = 0
		else:
			pro += s * p
			p = 0
	print(pro)


x = 0
t = int(input())
for i in range(t):
	b = 0
	f = 0
	p = 0
	h = 0
	c = 0
	x = 0
	line1 = input()
	a = line1.split()
	b = int(a[0])
	p = int(a[1])
	f = int(a[2])
	line2 = input()
	n = line2.split()
	h = int(n[0])
	c = int(n[1])
	if b > 1:
		if h > c:
			if b > p * 2:
				b = b - p * 2
				x = p * h
				if b // 2 > f:
					x = x + f * c
				else:
					x = x + c * (b // 2)
			else:
				x = h * (b // 2)
		elif b > f * 2:
			b = b - f * 2
			x = f * c
			if b // 2 > p:
				x = x + p * h
			else:
				x = x + h * (b // 2)
		else:
			x = c * (b // 2)
	else:
		x = 0
	print(x)


from sys import stdin
t = int(stdin.readline())
for i in range(0, t):
	(b, p, f) = (int(j) for j in stdin.readline().split())
	(h, c) = (int(j) for j in stdin.readline().split())
	total = 0
	b //= 2
	if c >= h:
		if b > f:
			total += f * c
			b -= f
			if b > p:
				total += p * h
			else:
				total += b * h
		else:
			total += b * c
	elif b > p:
		total += p * h
		b -= p
		if b > f:
			total += f * c
		else:
			total += b * c
	else:
		total += b * h
	print(total)


n = int(input())
for i in range(n):
	nums = list(map(int, input().split()))
	prices = list(map(int, input().split()))
	if nums[0] < 2:
		print(0)
	elif prices[0] > prices[1]:
		total = min(nums[0] // 2, nums[1] + nums[2])
		if nums[0] // 2 >= nums[1]:
			print(prices[0] * nums[1] + (total - nums[1]) * prices[1])
		else:
			print(prices[0] * (nums[0] // 2))
	else:
		total = min(nums[0] // 2, nums[1] + nums[2])
		if nums[0] // 2 >= nums[2]:
			print(prices[1] * nums[2] + (total - nums[2]) * prices[0])
		else:
			print(prices[1] * (nums[0] // 2))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(b, p, f) = M()
	x = b + 0
	(h, c) = M()
	ch = min(b // 2, f)
	b -= ch * 2
	hm = min(b // 2, p)
	b -= hm * 2
	ans = hm * h + ch * c
	hm = min(x // 2, p)
	x -= hm * 2
	ch = min(x // 2, f)
	x -= ch * 2
	ans2 = hm * h + ch * c
	print(max(ans, ans2))


t = int(input())
for k in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pr = 0
	if b == 1 or b == 0:
		print(0)
	else:
		if h > c:
			for i in range(p):
				if b > 1:
					pr += h
					b -= 2
			for i in range(f):
				if b > 1 and f > 0:
					pr += c
					f -= 1
					b -= 2
		else:
			for i in range(f):
				if b > 1:
					pr += c
					b -= 2
			for i in range(p):
				if b > 1 and p > 0:
					pr += h
					p -= 1
					b -= 2
		print(pr)


t = int(input())
while t > 0:
	t -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(max(h * max(min(int(b / 2), p), 0) + c * max(min(int(b / 2) - p, f), 0), c * max(min(int(b / 2), f), 0) + h * max(min(int(b / 2) - f, p), 0)))


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if c > h:
		ans = c * min(b // 2, f)
		b -= 2 * f
		ans += max(h * min(b // 2, p), 0)
	else:
		ans = h * min(b // 2, p)
		b -= 2 * p
		ans += max(c * min(b // 2, f), 0)
	print('%d\n' % ans)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
t = ii()
for a0 in range(t):
	(m, p, f) = mi()
	(h, c) = mi()
	m = m // 2
	if m >= p + f:
		print(h * p + f * c)
	else:
		x = 0
		if h >= c:
			x = min(m, p) * h
			m -= min(m, p)
			if m > 0:
				x += min(m, f) * c
		else:
			x = min(m, f) * c
			m -= min(m, f)
			if m > 0:
				x += min(m, p) * h
		print(x)


n = int(input())
while n:
	n -= 1
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	price = 0
	if h > c and b >= 2:
		price += min(p, b // 2) * h
		b -= price // h * 2
		if b > 1:
			price += min(f, b // 2) * c
	elif b >= 2:
		price += min(f, b // 2) * c
		b -= price // c * 2
		if b > 1:
			price += min(p, b // 2) * h
	print(price)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	mi = 0
	for i in range(b // 2 + 1):
		tot = 0
		bb = min(p, i)
		tot += bb * h
		cc = min((b - i * 2) // 2, f)
		tot += cc * c
		mi = max(mi, tot)
	print(mi)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	answer = 0
	for i in range(p + 1):
		for j in range(f + 1):
			if 2 * i + 2 * j <= b:
				answer = max(answer, i * h + j * c)
			else:
				break
	print(answer)


def main():
	t = int(input())
	for case in range(t):
		(noThreads, noCloths, noLeathers) = input().split()
		(costBag, costShoes) = input().split()
		noThreads = int(noThreads)
		noCloths = int(noCloths)
		noLeathers = int(noLeathers)
		costBag = int(costBag)
		costShoes = int(costShoes)
		profit = 0
		if costShoes > costBag:
			(noCloths, noLeathers) = swap(noCloths, noLeathers)
			(costBag, costShoes) = swap(costBag, costShoes)
		if noThreads > 2 * noCloths:
			noThreads = noThreads - 2 * noCloths
			profit += noCloths * costBag
			if noThreads > 2 * noLeathers:
				profit += noLeathers * costShoes
			else:
				profit += noThreads // 2 * costShoes
		else:
			profit += noThreads // 2 * costBag
		print(profit)

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)
main()


def profit_counter(bread, cow, chicken, cow_cost, chicken_cost):
	bread = bread // 2
	if cow_cost > chicken_cost:
		cow_b = min(bread, cow)
		bread -= cow_b
		chicken_b = min(bread, chicken)
	else:
		chicken_b = min(bread, chicken)
		bread -= chicken_b
		cow_b = min(bread, cow)
	profit = cow_b * cow_cost + chicken_b * chicken_cost
	print(profit)
t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	profit_counter(b, p, f, h, c)


def max_pay(b, p, f, h, c):
	pay = 0
	if h > c:
		if b // 2 >= p:
			pay += h * p
			b -= p * 2
			pay += b // 2 * c if b // 2 <= f else f * c
		else:
			pay += b // 2 * h
	elif b // 2 >= f:
		pay += c * f
		b -= f * 2
		pay += b // 2 * h if b // 2 <= p else p * h
	else:
		pay += b // 2 * c
	return pay
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(max_pay(b, p, f, h, c))


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().rstrip().split())
	(h, c) = map(int, input().rstrip().split())
	money = 0
	u = b // 2
	if h > c:
		if u >= p:
			money = money + h * p
			money = money + min(u - p, f) * c
		else:
			money = money + u * h
	elif u >= f:
		money = money + f * c
		money = money + min(u - f, p) * h
	else:
		money = money + u * c
	print(money)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	r1 = min(b // 2, p) * h + c * min(f, (b - min(b // 2, p) * 2) // 2)
	r2 = min((b - min(b // 2, f) * 2) // 2, p) * h + c * min(f, b // 2)
	print(max(r1, r2))


t = int(input())
for it in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	qqqqq = 0
	for iq in range(1000000):
		qqqqq += 1
	ans = 0
	if h > c:
		ans += min(p, b // 2)
		b -= ans * 2
		ans *= h
		ans += min(f, b // 2) * c
	else:
		ans += min(f, b // 2)
		b -= ans * 2
		ans *= c
		ans += min(p, b // 2) * h
	print(ans)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(b, p, f) = mi()
	(h, c) = mi()
	if h > c:
		x = h * min(b // 2, p)
		b -= p * 2
		if b > 0:
			x += c * min(b // 2, f)
	else:
		x = c * min(b // 2, f)
		b -= f * 2
		if b > 0:
			x += h * min(b // 2, p)
	print(x)


t = int(input())
for __ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if (p + f) * 2 <= b:
		print(p * h + f * c)
	elif b < 2:
		print('0')
	elif max(h, c) == c and b // 2 >= f:
		print(f * c + (b // 2 - f) * h)
	elif max(h, c) == c and b // 2 <= f:
		print(b // 2 * c)
	elif max(h, c) == h and b // 2 >= p:
		print(p * h + (b // 2 - p) * c)
	elif max(h, c) == h and b // 2 <= p:
		print(b // 2 * h)


t = int(input())
for _ in range(t):
	(b, p, f) = list(map(int, input().split(' ')))
	(h, c) = list(map(int, input().split(' ')))
	(maxProfit, hamburgers, chickenBurgers) = (0, 0, 0)
	if c > h:
		while b >= 2 and f > 0:
			chickenBurgers += 1
			b -= 2
			f -= 1
		while b >= 2 and p > 0:
			hamburgers += 1
			b -= 2
			p -= 1
	else:
		while b >= 2 and p > 0:
			hamburgers += 1
			b -= 2
			p -= 1
		while b >= 2 and f > 0:
			chickenBurgers += 1
			b -= 2
			f -= 1
	maxProfit = h * hamburgers + c * chickenBurgers
	print(maxProfit)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	r = 0
	b //= 2
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	cn = min(b, p)
	b -= cn
	p -= cn
	r += h * cn
	cnt = min(b, f)
	b -= cnt
	f -= cnt
	r += c * cnt
	print(r)


for _ in range(int(input())):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	b = int(b / 2)
	if h > c:
		total_hamburgers = min(b, p)
		print(h * total_hamburgers + c * min(f, b - total_hamburgers))
	else:
		total_chicken_burgers = min(f, b)
		print(c * total_chicken_burgers + h * min(p, b - total_chicken_burgers))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	sum = 0
	if e >= d:
		while a > 1 and c != 0:
			a = a - 2
			c = c - 1
			sum = sum + e
		while a > 1 and b != 0:
			a = a - 2
			b = b - 1
			sum = sum + d
	else:
		while a > 1 and b != 0:
			a = a - 2
			b = b - 1
			sum = sum + d
		while a > 1 and c != 0:
			a = a - 2
			c = c - 1
			sum = sum + e
	print(sum)


for _ in range(int(input())):
	(buns, ham, chicken) = [int(x) for x in input().split()]
	(hcost, ccost) = [int(x) for x in input().split()]
	profit = 0
	if ccost > hcost:
		cburg = min(buns // 2, chicken)
		profit = cburg * ccost
		hburg = min((buns - cburg * 2) // 2, ham)
		profit += hburg * hcost
	else:
		hburg = min(buns // 2, ham)
		profit = hburg * hcost
		cburg = min((buns - hburg * 2) // 2, chicken)
		profit += cburg * ccost
	print(profit)


t = int(input())
A = []
for i in range(t):
	sum = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		if b <= 2 * p:
			if b % 2 == 0:
				sum += b * h // 2
			else:
				sum += (b - 1) // 2 * h
		else:
			sum += p * h
			b -= p * 2
			if b <= 2 * f:
				if b % 2 == 0:
					sum += b * c // 2
				else:
					sum += (b - 1) // 2 * c
			else:
				sum += f * c
	elif b <= 2 * f:
		if b % 2 == 0:
			sum += b * c // 2
		else:
			sum += (b - 1) // 2 * c
	else:
		sum += f * c
		b -= f * 2
		if b <= 2 * p:
			if b % 2 == 0:
				sum += b * h // 2
			else:
				sum += (b - 1) // 2 * h
		else:
			sum += p * h
	A.append(sum)
for elem in A:
	print(elem)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		n = min(b // 2, p)
		b -= 2 * n
		p -= n
		answer = h * n
		n = min(b // 2, f)
		b -= 2 * n
		f -= n
		answer += c * n
	else:
		n = min(b // 2, f)
		b -= 2 * n
		f -= n
		answer = c * n
		n = min(b // 2, p)
		b -= 2 * n
		p -= n
		answer += h * n
	print(answer)


for i in range(int(input())):
	(bun, beef, chick) = map(int, input().split())
	(h, c) = map(int, input().split())
	bun = bun // 2
	if beef >= bun:
		mah = h * bun
	else:
		mah = h * beef + c * min(chick, bun - beef)
	if chick >= bun:
		mac = c * bun
	else:
		mac = c * chick + h * min(bun - chick, beef)
	print(max(mac, mah))


for _ in range(int(input())):
	(buns, patties, cutlets) = map(int, input().split())
	(pattiesP, cutletsP) = map(int, input().split())
	if pattiesP > cutletsP:
		burgers = min(buns // 2, patties)
		cburgers = min(buns // 2 - burgers, cutlets)
		print(burgers * pattiesP + cburgers * cutletsP)
	else:
		cburgers = min(buns // 2, cutlets)
		burgers = min(buns // 2 - cburgers, patties)
		print(burgers * pattiesP + cburgers * cutletsP)


t = int(input())
for i in range(0, t):
	am = input().split()
	b = int(am[0])
	p = int(am[1])
	f = int(am[2])
	pr = input().split()
	h = int(pr[0])
	c = int(pr[1])
	total = 0
	buncap = b // 2
	if h >= c:
		gpr = h
		gm = p
		lpr = c
		lm = f
	else:
		gpr = c
		gm = f
		lpr = h
		lm = p
	if buncap >= gm:
		buncap -= gm
		total += gpr * gm
		if lm >= buncap:
			total += buncap * lpr
		else:
			total += lm * lpr
	else:
		total += gpr * buncap
	print(total)


def GanaPeso(ingredientes, dinero):
	totales = int(ingredientes[0] / 2)
	if ingredientes[1] + ingredientes[2] <= totales:
		return ingredientes[1] * dinero[0] + ingredientes[2] * dinero[1]
	elif dinero[0] < dinero[1]:
		if ingredientes[2] >= totales:
			return dinero[1] * totales
		else:
			totales -= ingredientes[2]
			return dinero[1] * ingredientes[2] + totales * dinero[0]
	elif ingredientes[1] >= totales:
		return dinero[0] * totales
	else:
		totales -= ingredientes[1]
		return dinero[0] * ingredientes[1] + totales * dinero[1]
queries = int(input())
for i in range(queries):
	ingredientes = input().split(' ')
	for i in range(len(ingredientes)):
		ingredientes[i] = int(ingredientes[i])
	dinero = input().split(' ')
	for d in range(len(dinero)):
		dinero[d] = int(dinero[d])
	print(GanaPeso(ingredientes, dinero))


n = int(input())
for i in range(0, n):
	P = input().rstrip().split(' ')
	b = int(P[0])
	p = int(P[1])
	f = int(P[2])
	u = input().rstrip().split(' ')
	if int(u[0]) >= int(u[1]):
		S = 0
		A = b // 2
		B = p // 1
		S += min(A, B) * int(u[0])
		b = b - min(A, B) * 2
		A = b // 2
		B = f // 1
		S += min(A, B) * int(u[1])
		print(S)
	else:
		S = 0
		A = b // 2
		B = f // 1
		S += min(A, B) * int(u[1])
		b = b - min(A, B) * 2
		A = b // 2
		B = p // 1
		S += min(A, B) * int(u[0])
		print(S)


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10 ** 6)

def SI():
	return input().split()

def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
YN = ['Yes', 'No']
mo = 10 ** 9 + 7

def solve():
	(b, p, f) = MI()
	(h, c) = MI()
	(h, p)
	(c, f)
	pr = 0
	pr += h * min(p, b // 2)
	nh = 2 * min(p, b // 2)
	pr += c * min(f, max(0, b - nh) // 2)
	ans = pr
	pr = 0
	pr += c * min(f, b // 2)
	nh = 2 * min(f, b // 2)
	pr += h * min(p, max(0, b - nh) // 2)
	ans = max(ans, pr)
	print(ans)
t = I()
for _ in range(t):
	solve()


def sol(bun, a, amoney, b, bmoney):
	ans = int(0)
	if bun % 2 == 1:
		bun -= 1
	if bun >= a * 2:
		ans += a * amoney
		bun -= a * 2
	else:
		ans += bun * amoney / 2
		bun = 0
	if bun >= b * 2:
		ans += b * bmoney
		bun -= b * 2
	else:
		ans += bun * bmoney / 2
	return int(ans)
test = int(input())
for i in range(test):
	(bun, beef, chicken) = map(int, input().split())
	(moneyOfBeef, moneyOfChicken) = map(int, input().split())
	print(max(sol(bun, beef, moneyOfBeef, chicken, moneyOfChicken), sol(bun, chicken, moneyOfChicken, beef, moneyOfBeef)))


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	b //= 2
	if c > h:
		(p, f) = (f, p)
		(h, c) = (c, h)
	if b <= p:
		print(b * h)
	else:
		print(p * h + min([b - p, f]) * c)


n = int(input())
for _ in range(n):
	(j, k) = (0, 0)
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		j = min(p, b // 2)
		k += h * j
		k += c * min(f, b // 2 - j)
	else:
		j = min(f, b // 2)
		k += c * j
		k += h * min(p, b // 2 - j)
	print(k)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if h > c and 2 * p < b:
		profit += h * p
		b -= 2 * p
		b = b // 2
		profit += c * min(b, f)
	elif c > h and 2 * f < b:
		profit += c * f
		b -= 2 * f
		b = b // 2
		profit += h * min(b, p)
	elif h == c and 2 * (p + f) < b:
		profit = h * (p + f)
	elif b < 2:
		profit = 0
	else:
		profit = b // 2 * max(h, c)
	print(profit)


t = int(input())
for i in range(t):
	b = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	prices = 0
	if h[0] > h[1]:
		while b[1] != 0 and b[0] > 1:
			prices += h[0]
			b[0] -= 2
			b[1] -= 1
		while b[2] != 0 and b[0] > 1:
			prices += h[1]
			b[0] -= 2
			b[2] -= 1
		print(prices)
	else:
		while b[2] != 0 and b[0] > 1:
			prices += h[1]
			b[0] -= 2
			b[2] -= 1
		while b[1] != 0 and b[0] > 1:
			prices += h[0]
			b[0] -= 2
			b[1] -= 1
		print(prices)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	money1 = min(b // 2, p) * h + min((b - min(b // 2, p) * 2) // 2, f) * c
	money2 = min(b // 2, f) * c + min((b - min(b // 2, f) * 2) // 2, p) * h
	print(max(money1, money2))


t = int(input())
for _ in range(t):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	num_burgers = b // 2
	ans = 0
	if h > c:
		ma = h
		n_ma = p
		mi = c
		n_mi = f
	else:
		ma = c
		n_ma = f
		mi = h
		n_mi = p
	while num_burgers > 0 and n_ma > 0:
		ans += ma
		n_ma -= 1
		num_burgers -= 1
	while num_burgers > 0 and n_mi > 0:
		ans += mi
		n_mi -= 1
		num_burgers -= 1
	print(ans)


n = int(input())
for i in range(n):
	(a, b, d) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	a //= 2
	if h < c:
		(h, c) = (c, h)
		(b, d) = (d, b)
	if b >= a:
		print(a * h)
	else:
		print(b * h + min(a - b, d) * c)


num_cases = int(input())

def profit_calc(patty_1, patty_2, price_1, price_2, num_buns):
	num_burger_type1 = min(patty_1, int(num_buns / 2))
	num_buns -= num_burger_type1 * 2
	num_burger_type2 = min(patty_2, int(num_buns / 2))
	profit = num_burger_type1 * price_1 + num_burger_type2 * price_2
	return profit
for current_case in range(num_cases):
	inp1 = input()
	inp1 = inp1.split(' ')
	inp2 = input()
	inp2 = inp2.split(' ')
	num_buns = int(inp1[0])
	num_beef = int(inp1[1])
	num_chicken = int(inp1[2])
	price_beef = int(inp2[0])
	price_chicken = int(inp2[1])
	profit = 0
	if price_beef >= price_chicken:
		print(profit_calc(num_beef, num_chicken, price_beef, price_chicken, num_buns))
	else:
		print(profit_calc(num_chicken, num_beef, price_chicken, price_beef, num_buns))


i = int(input())
for j in range(i):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	sum = 0
	if b[0] < b[1]:
		m = min(a[2], a[0] / 2)
		sum += b[1] * int(m)
		a[0] = a[0] - m * 2
		m = min(a[1], a[0] / 2)
		sum += b[0] * int(m)
	else:
		m = min(a[1], a[0] / 2)
		sum += b[0] * int(m)
		a[0] = a[0] - m * 2
		m = min(a[2], a[0] / 2)
		sum += b[1] * int(m)
	print(sum)


zap = int(input())
array = []
for j in range(zap):
	arr_0 = []
	arr_0.append([int(i) for i in filter(None, input().split(' '))])
	arr_0.append([int(i) for i in filter(None, input().split(' '))])
	array.append(arr_0)
for j in range(zap):
	arr = array[j][0]
	b = arr[0]
	ham = arr[1]
	chik = arr[2]
	arr = []
	arr = array[j][1]
	s_ham = arr[0]
	s_chik = arr[1]
	sum = 0
	if s_chik > s_ham:
		while b > 1 and chik > 0:
			sum += s_chik
			chik -= 1
			b -= 2
		while b > 1 and ham > 0:
			sum += s_ham
			ham -= 1
			b -= 2
	else:
		while b > 1 and ham > 0:
			sum += s_ham
			ham -= 1
			b -= 2
		while b > 1 and chik > 0:
			sum += s_chik
			chik -= 1
			b -= 2
	print(sum)


for _ in range(int(input())):
	(b, c, p) = map(int, input().split())
	(ham, ch) = map(int, input().split())
	sum = 0
	if ch > ham:
		while b > 1 and (p != 0 or c != 0):
			if p > 0:
				b = b - 2
				p = p - 1
				sum = sum + ch
			else:
				b = b - 2
				c = c - 1
				sum = sum + ham
	else:
		while b > 1 and (p != 0 or c != 0):
			if c > 0:
				b = b - 2
				c = c - 1
				sum = sum + ham
			else:
				b = b - 2
				p = p - 1
				sum = sum + ch
	print(sum)


t = int(input())
for k in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	ready = b // 2
	if ready < 1:
		cnt = 0
	else:
		if c > h:
			(exp, i_exp) = (c, f)
			(n_exp, i_nexp) = (h, p)
		else:
			(exp, i_exp) = (h, p)
			(n_exp, i_nexp) = (c, f)
		used = min(ready, i_exp)
		cnt = exp * used + n_exp * min(ready - used, i_nexp)
	print(cnt)


def calculate(buns, item, itemcost):
	cost = 0
	while item != 0:
		if buns - 2 >= 0:
			item -= 1
			cost += itemcost
			buns -= 2
		else:
			break
	return (cost, buns)
n = int(input())
for i in range(n):
	res = list(map(int, input().split()))
	costs = list(map(int, input().split()))
	profit = 0
	buns = res[0]
	beef = res[1]
	chicken = res[2]
	beefcost = costs[0]
	chickencost = costs[1]
	if beefcost > chickencost:
		(result, buns) = calculate(buns, beef, beefcost)
		profit += result
		(result, buns) = calculate(buns, chicken, chickencost)
		profit += result
	else:
		(result, buns) = calculate(buns, chicken, chickencost)
		profit += result
		(result, buns) = calculate(buns, beef, beefcost)
		profit += result
	print(profit)


total = int(input())
for i in range(total):
	(b, p, f) = [int(x) for x in input().split()]
	(hv, cv) = [int(x) for x in input().split()]
	if hv > cv:
		nh = int(min(int(b / 2), p))
		nc = min(int((b - 2 * nh) / 2), f)
		print(nh * hv + nc * cv)
	else:
		nc = int(min(b / 2, f))
		nh = min(int((b - 2 * nc) / 2), p)
		print(nh * hv + nc * cv)


(n,) = map(int, input().split())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(pc, fc) = map(int, input().split())
	if fc < pc:
		(p, f) = (f, p)
		(pc, fc) = (fc, pc)
	if b - f * 2 <= 0:
		print(b // 2 * fc)
	elif b - f * 2 - p * 2 <= 0:
		print(f * fc + (b // 2 - f) * pc)
	else:
		print(f * fc + p * pc)


x = int(input())
z = 0
l = []
e = 0
while z < x:
	(a, b, c) = map(int, input().split())
	(hum, chek) = map(int, input().split())
	if a == 1:
		l.append(0)
		z += 1
		continue
	if a % 2 == 0:
		even = a / 2
	else:
		even = (a - 1) / 2
	if max(hum, chek) == chek:
		max1 = c
		min1 = b
		big = chek
		sm = hum
	else:
		max1 = b
		min1 = c
		big = hum
		sm = chek
	q = 1
	while q <= even and q <= max1:
		e += big
		q += 1
	s = even - (q - 1)
	q = 1
	while q <= s and q <= min1:
		e += sm
		q += 1
	l.append(e)
	e = 0
	z += 1
z = 0
while z < len(l):
	print(l[z])
	z += 1


def compute_a(b, p, f, x, y):
	c = 0
	if b >= p * 2:
		c += p * x
		b = b - p * 2
	else:
		m = p * 2 - b
		if m & 1 == 1:
			m = m + 1
		m = m // 2
		m = p - m
		c += m * x
		b = b - m * 2
	if b >= f * 2:
		c += f * y
		b = b - f * 2
	else:
		m = f * 2 - b
		if m & 1 == 1:
			m = m + 1
		m = m // 2
		m = f - m
		c += m * y
		b = b - m * 2
	return c

def compute_b(b, p, f, x, y):
	c = 0
	if b >= f * 2:
		c += f * y
		b = b - f * 2
	else:
		m = f * 2 - b
		if m & 1 == 1:
			m = m + 1
		m = m // 2
		m = f - m
		c += m * y
		b = b - m * 2
	if b >= p * 2:
		c += p * x
		b = b - p * 2
	else:
		m = p * 2 - b
		if m & 1 == 1:
			m = m + 1
		m = m // 2
		m = p - m
		c += m * x
		b = b - m * 2
	return c
t = int(input())
for o in range(t):
	(b, p, f) = map(int, input().split())
	(x, y) = map(int, input().split())
	l = compute_a(b, p, f, x, y)
	m = compute_b(b, p, f, x, y)
	print(max(l, m))


n = int(input())
for i in range(0, n):
	d = input()
	s = input()
	d1 = list(d.split())
	b = int(d1[0])
	p = int(d1[1])
	f = int(d1[2])
	s1 = list(s.split())
	h = int(s1[0])
	c = int(s1[1])
	if b == 1:
		print(0)
	if h >= c and b != 1:
		pricep = min(int(b / 2), p) * h
		b = b - min(p, b / 2) * 2
		total = min(int(b / 2), f) * c
		print(pricep + total)
	if c > h and b != 1:
		pricef = min(int(b / 2), f) * c
		b = b - min(f, b / 2) * 2
		total = min(int(b / 2), p) * h
		print(pricef + total)


queries = int(input())
for i in range(queries):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	if c >= h:
		if 2 * f > b:
			b = b // 2
			profit += b * c
		else:
			b -= 2 * f
			profit += c * f
			if 2 * p > b:
				b = b // 2
				profit += b * h
			else:
				b -= 2 * p
				profit += p * h
	elif 2 * p > b:
		b = b // 2
		profit += b * h
	else:
		b -= 2 * p
		profit += h * p
		if 2 * f > b:
			b = b // 2
			profit += b * c
		else:
			b -= 2 * f
			profit += f * c
	print(profit)


tc = int(input())
for i in range(tc):
	A = input().split()
	B = input().split()
	A[0] = int(A[0])
	if A[0] == 1:
		print(0)
	elif int(B[1]) >= int(B[0]):
		cnt1 = 0
		cnt2 = 0
		for i in range(int(A[-1])):
			A[0] = A[0] - 2
			cnt1 = cnt1 + 1
			if A[0] <= 1:
				break
		for i in range(int(A[1])):
			if A[0] <= 1:
				break
			A[0] = A[0] - 2
			cnt2 = cnt2 + 1
			if A[0] <= 1:
				break
		amnt = int(B[1]) * cnt1 + int(B[0]) * cnt2
		print(amnt)
	else:
		cnt1 = 0
		cnt2 = 0
		for i in range(int(A[1])):
			A[0] = A[0] - 2
			cnt1 = cnt1 + 1
			if A[0] <= 1:
				break
		for i in range(int(A[-1])):
			if A[0] <= 1:
				break
			A[0] = A[0] - 2
			cnt2 = cnt2 + 1
			if A[0] <= 1:
				break
		amnt = int(B[0]) * cnt1 + int(B[1]) * cnt2
		print(amnt)


import sys
from collections import defaultdict
import math

def main():
	t = int(input())
	for _ in range(t):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		if h > c:
			burg = min(b // 2, p)
			cut = min((b - 2 * burg) // 2, f)
		else:
			cut = min(b // 2, f)
			burg = min((b - cut * 2) // 2, p)
		ans = burg * h + cut * c
		print(ans)
main()


I = lambda : map(int, input().split())
for i in '*' * int(input()):
	(b, p, f) = I()
	(h, c) = I()
	if h > c:
		o = min(b // 2, p)
		b -= o * 2
		print(h * o + min(b // 2, f) * c)
	else:
		o = min(b // 2, f)
		b -= o * 2
		print(c * o + min(b // 2, p) * h)


for i in range(int(input())):
	(b, y1, y2) = map(int, input().split())
	(x1, x2) = map(int, input().split())
	if x1 < x2:
		(x1, x2, y1, y2) = (x2, x1, y2, y1)
	print(x1 * min(b // 2, y1) + x2 * max(min((b - 2 * y1) // 2, y2), 0))


import math
t = int(input())
for i in range(t):
	(b, p, f) = input().split()
	(h, c) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	s = 0
	if h < c:
		(p, f) = (f, p)
		(c, h) = (h, c)
	while b > 1 and p > 0:
		d = int(min(p, b / 2))
		s += d * h
		p -= d
		b -= 2 * d
	while b > 1 and f > 0:
		d = int(min(f, b / 2))
		s += d * c
		f -= d
		b -= 2 * d
	print(int(s))


false = False
true = True
null = None
TEST = false
try:
	import sys
	for arg in sys.argv:
		if arg == 'test':
			print('test mode')
			TEST = True
	pass
except:
	pass

def AddImports(libraryNames):
	for libname in libraryNames:
		if type(libname) == type(tuple()):
			short = libname[1]
			libname = libname[0]
		else:
			short = None
		try:
			lib = __import__(libname)
		except ImportError:
			pass
		else:
			if short:
				globals()[short] = lib
			else:
				globals()[libname] = lib
	return True
libnames = ['functools', 'math', 'collections']
AddImports(libnames)
IntellisenseHint = False
if IntellisenseHint:
	import functools
	import math
	import collections

def it(args, *arg):
	if TEST:
		print(args, *arg)

def floatEqual(a, b):
	diff = math.fabs(a - b)
	if diff < 1e-10:
		return True
	else:
		return diff <= 1e-08 * max(math.fabs(a), math.fabs(b))

def ria():
	return list(map(int, input().strip(' ').split(' ')))

def rsa():
	return list(map(str, input().strip('\n').split(' ')))

def create2DArray(rows, cols, val=False):
	return [[val for c in range(cols)] for r in range(rows)]

def create3DArray(zs, ys, xs, val=False):
	return [[[val for x in range(xs)] for y in range(ys)] for z in range(zs)]

def print2DArray(array):
	for r in range(len(array)):
		it(*array[r])
from sys import stdin
input = stdin.readline
import copy
from collections import deque
sys.setrecursionlimit(10000)

def solve():
	T = ria()[0]
	for t in range(T):
		(b, p, f) = ria()
		(h, c) = ria()
		(np, nf) = (min(b // 2, p), 0)
		maxv = h * np
		while True:
			nf += 1
			if nf > f:
				break
			if np * 2 + nf * 2 > b:
				if np == 0:
					break
				np -= 1
			maxv = max(maxv, h * np + c * nf)
		print(maxv)
	pass
solve()


n = int(input())
for i in range(n):
	(b, g, k) = map(int, input().split())
	b //= 2
	(gg, kk) = map(int, input().split())
	m = 0
	if gg < kk:
		(gg, kk) = (kk, gg)
		(g, k) = (k, g)
	if g >= b:
		m += gg * b
	else:
		b -= g
		m += gg * g
		if k >= b:
			m += kk * b
		else:
			m += kk * k
	print(m)


repeat = int(input())
(ham, cut) = (0, 0)
res = []
for m in range(repeat):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		if p * 2 < b:
			b -= p * 2
			ham = p
		else:
			ham = int(b / 2)
			b = 0
		if f * 2 < b:
			cut = f
		else:
			cut = int(b / 2)
	else:
		if f * 2 < b:
			b -= f * 2
			cut = f
		else:
			cut = int(b / 2)
			b = 0
		if p * 2 < b:
			ham = p
		else:
			ham = int(b / 2)
	res.append(ham * h + cut * c)
for m in res:
	print(m)


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	co = 0
	if d > e:
		ans = min(b, a // 2)
		co += ans * d
		a -= ans * 2
		ans = min(c, a // 2)
		co += ans * e
		print(co)
	else:
		ans = min(c, a // 2)
		co += ans * e
		a -= ans * 2
		ans = min(b, a // 2)
		co += ans * d
		print(co)


t = int(input())
for k in range(t):
	(b, p, f) = list(map(lambda x: int(x), input().split(' ')))
	(h, c) = list(map(lambda x: int(x), input().split(' ')))
	max_b = b // 2
	max_sum = 0
	if h > c:
		max_sum += min(max_b, p)
		max_b -= max_sum
		max_sum *= h
		max_sum += min(max_b, f) * c
	else:
		max_sum += min(max_b, f)
		max_b -= max_sum
		max_sum *= c
		max_sum += min(max_b, p) * h
	print(max_sum)


out = ''
n = int(input())
for order in range(n):
	profit = 0
	(b, p, f) = list(map(int, input().split()))
	if b % 2 == 1:
		b = b - 1
	b = b / 2
	(h, c) = list(map(int, input().split()))
	if h > c:
		cheap = [c, f]
		expensive = [h, p]
	else:
		cheap = [h, p]
		expensive = [c, f]
	if b >= expensive[1]:
		profit = expensive[0] * expensive[1]
		b = b - expensive[1]
		if b >= cheap[1]:
			profit = profit + cheap[0] * cheap[1]
		else:
			profit = profit + cheap[0] * b
	else:
		profit = expensive[0] * b
	out = out + str(int(profit)) + '\n'
cleaned = out.rstrip()
print(cleaned)


def count_benefit(buns, expensive_cost, expensive_count, cheap_cost, cheap_count):
	benefit = 0
	expensive = expensive_count if buns // 2 > expensive_count else buns // 2
	benefit += expensive * expensive_cost
	buns -= expensive * 2
	cheap = cheap_count if buns // 2 > cheap_count else buns // 2
	benefit += cheap_cost * cheap
	return benefit
t = int(input())
result = []
for i in range(0, t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		result = result + [count_benefit(b, h, p, c, f)]
	else:
		result = result + [count_benefit(b, c, f, h, p)]
for i in result:
	print(i)


t = int(input())
while t:
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans1 = 0
	ans2 = 0
	x = min(b // 2, p)
	y = min(b // 2, f)
	ans1 += x * h
	z = b - 2 * x
	ans1 += min(z // 2, f) * c
	ans2 += y * c
	w = b - 2 * y
	ans2 += min(w // 2, p) * h
	print(max(ans1, ans2))
	t -= 1


n = int(input())
r = []
b = []
for i in range(n):
	s = 0
	b.append(list(map(int, input().split())))
	r.append(list(map(int, input().split())))
	x = b[i][0] // 2
	a = b[i][r[i].index(max(r[i])) + 1]
	c = b[i][r[i].index(min(r[i])) + 1]
	if x >= a:
		x = x - a
		s += a * max(r[i])
		if x >= c:
			s += c * min(r[i])
		elif x < c:
			s += x * min(r[i])
	elif x < a:
		s += x * max(r[i])
	print(s)


def burger_profit():
	t = int(input())
	for i in range(t):
		first_line = list(map(int, input().split()))
		buns = first_line[0]
		patties = first_line[1]
		cutlet = first_line[2]
		second_line = list(map(int, input().split()))
		hamburger_price = second_line[0]
		chicken_burger_price = second_line[1]
		total_profit = 0
		if hamburger_price >= chicken_burger_price:
			if int(buns / 2) >= patties:
				total_profit += patties * hamburger_price
				remain_buns = buns - patties * 2
				if int(remain_buns / 2) >= cutlet:
					total_profit += cutlet * chicken_burger_price
				elif int(remain_buns / 2) < cutlet:
					total_profit += int(remain_buns / 2) * chicken_burger_price
			elif int(buns / 2) < patties:
				total_profit += int(buns / 2) * hamburger_price
		elif hamburger_price < chicken_burger_price:
			if int(buns / 2) >= cutlet:
				total_profit += cutlet * chicken_burger_price
				remain_buns = buns - cutlet * 2
				if int(remain_buns / 2) >= patties:
					total_profit += patties * hamburger_price
				elif int(remain_buns / 2) < patties:
					total_profit += int(remain_buns / 2) * hamburger_price
			elif int(buns / 2) < cutlet:
				total_profit += int(buns / 2) * chicken_burger_price
		print(total_profit)
burger_profit()


import math
t = int(input())
s = []
for i in range(t):
	(b, p, f) = input().split()
	(h, c) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	b = b // 2
	if h > c:
		if p >= b:
			summ = h * b
		else:
			summ = h * p + c * min(f, b - p)
	elif f >= b:
		summ = c * b
	else:
		summ = c * f + h * min(p, b - f)
	s.append(summ)
for i in range(len(s)):
	print(s[i])


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	z = list(map(int, input().split()))
	y = list(map(int, input().split()))
	duit = 0
	if y[1] > y[0]:
		temp = min(z[0] // 2, z[2])
		duit += temp * y[1]
		z[0] -= temp * 2
		z[2] -= temp
		while z[0] > 1 and z[1] > 0:
			duit += y[0]
			z[0] -= 2
			z[1] -= 1
	else:
		temp = min(z[0] // 2, z[1])
		duit += temp * y[0]
		z[0] -= temp * 2
		z[1] -= temp
		while z[0] > 1 and z[2] > 0:
			duit += y[1]
			z[0] -= 2
			z[2] -= 1
	stdout.write(str(duit))
	stdout.write('\n')


n = int(input())
for i in range(n):
	(b, c, d) = list(map(int, input().split()))
	(e, f) = list(map(int, input().split()))
	ans = 0
	if f > e:
		ans += min(b // 2, d) * f
		b -= min(b // 2 * 2, d * 2)
		if b > 1:
			ans += min(b // 2, c) * e
	else:
		ans += min(b // 2, c) * e
		b -= min(b // 2 * 2, c * 2)
		if b > 1:
			ans += min(b // 2, d) * f
	print(ans)


from typing import Tuple

def calc_possibly_burgers(buns: int, cutlets: int) -> Tuple[int, int]:
	if cutlets * 2 <= buns:
		burgers = cutlets
		bun_remains = buns - cutlets * 2
		return (burgers, bun_remains)
	else:
		burgers = buns // 2
		return (burgers, buns - burgers * 2)

def main():
	t = int(input())
	prices = []
	for i in range(t):
		(b, p, f) = map(int, input().split(' '))
		(h, c) = map(int, input().split(' '))
		if h > c:
			(burgers, bun_remains) = calc_possibly_burgers(b, p)
			burger_income = burgers * h
			if bun_remains <= 1:
				prices.append(burger_income)
			else:
				(chickenburgers, bun_remains) = calc_possibly_burgers(bun_remains, f)
				chickenburger_income = chickenburgers * c
				prices.append(burger_income + chickenburger_income)
		else:
			(chickenburgers, bun_remains) = calc_possibly_burgers(b, f)
			chickenburger_income = chickenburgers * c
			if bun_remains <= 1:
				prices.append(chickenburger_income)
			else:
				(burgers, bun_remains) = calc_possibly_burgers(bun_remains, p)
				burger_income = burgers * h
				prices.append(burger_income + chickenburger_income)
	for i in prices:
		print(i)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def pro(k, l, n):
	if l < n:
		if k == 0:
			return n - l
		return n - l + 2
	if l == n:
		if k == 0:
			return 0
		elif k == 1:
			return 1
		return 3
	else:
		l -= n - 1
		if l == k:
			return 1
		elif l > k:
			return 0
		if l < k - 1:
			return 2
		else:
			return 3

def rt(k, l, n):
	if k < n:
		if l == 0:
			return k * 2 + n
		return n + k * 2 - 1
	elif k == n:
		if l == 1:
			return k * 3 - 2
		elif l == 0:
			return k * 3
		return k * 3 - 3
	else:
		k -= n - 1
		if k == l:
			return n * 3 - 2
		elif k > l:
			return n * 3
		if k < l - 1:
			return (n - 1) * 3 - 1
		else:
			return (n - 1) * 3

def main():
	(a, s, d) = rinput()
	(n, m) = rinput()
	a = a // 2
	if n > m:
		if s <= a:
			print(s * n + m * min(a - s, d))
			return 0
		else:
			print(a * n)
			return 0
	(n, s, m, d) = (m, d, n, s)
	if s <= a:
		print(s * n + m * min(a - s, d))
		return 0
	else:
		print(a * n)
		return 0
for i in range(iinput()):
	main()


t = int(input())
while t != 0:
	(pao, carne, frango) = input().split()
	(pao, carne, frango) = (int(pao), int(carne), int(frango))
	(p_carne, p_frango) = input().split()
	(p_carne, p_frango) = (int(p_carne), int(p_frango))
	res = 0
	if p_carne > p_frango:
		caro = p_carne
		caro_count = carne
		barato = p_frango
		barato_count = frango
	else:
		caro = p_frango
		caro_count = frango
		barato = p_carne
		barato_count = carne
	res = 0
	while caro_count > 0 and pao >= 2:
		pao -= 2
		caro_count -= 1
		res += caro
	while barato_count > 0 and pao >= 2:
		pao -= 2
		barato_count -= 1
		res += barato
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if h < c:
		(h, c) = (c, h)
		(p, f) = (f, p)
	r = 0
	d = min(b, p)
	b -= d
	p -= d
	r += h * d
	d = min(b, f)
	b -= d
	f -= d
	r += c * d
	print(r)


t = int(input())
for i in range(t):
	(b, p, c) = map(int, input().split())
	(h, cb) = map(int, input().split())
	b = b // 2
	if h > cb:
		n = min(b, p)
		b = b - n
		print(h * n + cb * min(b, c))
	else:
		n = min(b, c)
		b = b - n
		print(cb * n + h * min(b, p))


z = input
for _ in range(int(z())):
	(b, p, f) = list(map(int, z().split()))
	(e, g) = list(map(int, z().split()))
	if e > g:
		c2 = min(b // 2, p)
		c1 = min((b - c2 * 2) // 2, f)
		print(c1 * g + c2 * e)
	else:
		c2 = min(b // 2, f)
		c1 = min((b - c2 * 2) // 2, p)
		print(c1 * e + c2 * g)


for tc in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	burg = min(b // 2, p + f)
	if h > c:
		ma = h
		mi = c
		k = p
	else:
		ma = c
		mi = h
		k = f
	ans = min(burg, k) * ma
	if min(burg, k) != burg:
		ans += (burg - k) * mi
	print(ans)


t = int(input())
for i in range(t):
	s = [int(i) for i in filter(None, input().split(' '))]
	b = s[0]
	g = s[1]
	k = s[2]
	s = [int(i) for i in filter(None, input().split(' '))]
	cg = s[0]
	ck = s[1]
	if cg > ck:
		if b // 2 > g:
			if b // 2 - g > k:
				print(g * cg + k * ck)
			else:
				print(g * cg + (b // 2 - g) * ck)
		else:
			print(b // 2 * cg)
	elif b // 2 > k:
		if b // 2 - k > g:
			print(k * ck + g * cg)
		else:
			print(k * ck + (b // 2 - k) * cg)
	else:
		print(b // 2 * ck)


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	f = a // 2
	p = 0
	if d > e and f >= b:
		p += b * d
		f = f - b
		p += min(f, c) * e
	elif e >= d and f >= c:
		p += c * e
		f = f - c
		p += min(f, b) * d
	elif d > e:
		p += f * d
	else:
		p += f * e
	print(p)


from sys import stdin, stdout
for q in range(int(input())):
	(b, p, f) = map(int, stdin.readline().split())
	(h, c) = map(int, stdin.readline().split())
	ans = 0
	if c > h:
		(c, h) = (h, c)
		(p, f) = (f, p)
	ans += min(p, b // 2) * h
	b -= min(p, b // 2) * 2
	ans += min(f, b // 2) * c
	print(ans)


import sys

def main(arr):
	for t in arr:
		b = int(t[0] / 2)
		m1 = min(b, t[1])
		ans1 = m1 * t[3] + min(b - m1, t[2]) * t[4]
		m2 = min(b, t[2])
		ans2 = m2 * t[4] + min(b - m2, t[1]) * t[3]
		ans = max(ans1, ans2)
		print(ans)

def read(f):
	n = int(f.readline().rstrip('\n'))
	d = []
	for i in range(n):
		tmp = []
		tmp += [int(x) for x in f.readline().split(' ')]
		tmp += [int(x) for x in f.readline().split(' ')]
		d.append(tmp)
	main(d)
read(sys.stdin)


t = int(input())
for i in range(t):
	result = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	buns = b // 2
	if c > h:
		while buns != 0 and f != 0:
			result = result + c
			buns -= 1
			f -= 1
		while buns != 0 and p != 0:
			result += h
			buns -= 1
			p -= 1
	else:
		while buns != 0 and p != 0:
			result += h
			buns -= 1
			p -= 1
		while buns != 0 and f != 0:
			result = result + c
			buns -= 1
			f -= 1
	print(result)


T = int(input())
for t in range(T):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	ans = 0
	if h > c:
		n = min(b // 2, p)
		ans += n * h
		b -= n * 2
		n = min(b // 2, f)
		ans += n * c
	else:
		n = min(b // 2, f)
		ans += n * c
		b -= n * 2
		n = min(b // 2, p)
		ans += n * h
	print(ans)


n = int(input())
burgers = []
for i in range(n):
	(b, p, f) = map(int, input().split())
	(ham, chick) = map(int, input().split())
	burger = 0
	if ham >= chick:
		hbur = min(int(b / 2), p)
		cbur = min(int((b - hbur * 2) / 2), f)
		burger = hbur * ham + cbur * chick
		burgers.append(burger)
	else:
		cbur = min(int(b / 2), f)
		hbur = min(int((b - cbur * 2) / 2), p)
		burger = hbur * ham + cbur * chick
		burgers.append(burger)
for burger in burgers:
	print(burger)


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	total = 0
	num_g = min(b // 2, p)
	num_c = min(b // 2, f)
	if h > c or (h == c and num_g > num_c):
		num_g = min(b // 2, p)
		total += num_g * h
		b -= num_g * 2
		num_c = min(f, b // 2)
		total += num_c * c
		print(total)
	else:
		num_c = min(f, b // 2)
		total += num_c * c
		b -= num_c * 2
		num_g = min(b // 2, p)
		total += num_g * h
		print(total)


n = int(input())
for x in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	s = []
	z = [p]
	z.append(f)
	y = [h]
	y.append(c)
	a = b // 2
	t = y.index(max(y))
	if z[t] <= a:
		s.append(z[t] * max(y))
		if z[1 - t] <= a - z[t]:
			s.append(z[1 - t] * min(y))
		else:
			s.append((a - z[t]) * min(y))
	else:
		s.append(a * max(y))
	print(sum(s))


count = int(input())
for i in range(count):
	bun_beef_chicken = input().split(' ')
	bun = int(bun_beef_chicken[0])
	beef = int(bun_beef_chicken[1])
	chicken = int(bun_beef_chicken[2])
	h_c = input().split(' ')
	h = int(h_c[0])
	c = int(h_c[1])
	if h > c:
		hamburger_count = min(int(bun / 2), beef)
		bun -= 2 * hamburger_count
		beef -= hamburger_count
		cheese_count = min(int(bun / 2), chicken)
		bun -= 2 * cheese_count
		chicken -= cheese_count
		print(h * hamburger_count + c * cheese_count)
	elif h < c:
		cheese_count = min(int(bun / 2), chicken)
		bun -= 2 * cheese_count
		chicken -= cheese_count
		hamburger_count = min(int(bun / 2), beef)
		bun -= 2 * hamburger_count
		beef -= hamburger_count
		print(h * hamburger_count + c * cheese_count)
	elif int(bun / 2) > beef + chicken:
		print(c * (beef + chicken))
	else:
		print(c * int(bun / 2))


def revenue(b, p, f, h, c):
	pur1 = min(b // 2, p if h > c else f)
	pur2 = min((b - 2 * pur1) // 2, f if h > c else p)
	rev = pur1 * max(h, c) + pur2 * min(h, c)
	return rev
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	print(revenue(b, p, f, h, c))


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		burgers = min(b // 2, p)
		b -= burgers * 2
		chicken = min(b // 2, f)
		print(burgers * h + chicken * c)
	else:
		chicken = min(b // 2, f)
		b -= chicken * 2
		burgers = min(b // 2, p)
		print(burgers * h + chicken * c)


t = int(input())
for i in range(t):
	(b, p, f) = [int(s) for s in input().split()]
	(h, c) = [int(s) for s in input().split()]
	pro = 0
	if h >= c:
		n = min(b // 2, p)
		b -= 2 * n
		pro += n * h
		n = min(b // 2, f)
		pro += n * c
	else:
		n = min(b // 2, f)
		b -= 2 * n
		pro += n * c
		n = min(b // 2, p)
		pro += n * h
	print(pro)


n = int(input().strip())
for i in range(n):
	(bun, beef, cut) = [int(x) for x in input().strip().split()]
	(h, c) = [int(x) for x in input().strip().split()]
	s = int(bun / 2)
	p = 0
	if h > c:
		p += min(s, beef) * h
		s -= min(s, beef)
		if s > 0:
			p += min(s, cut) * c
	else:
		p += min(s, cut) * c
		s -= min(s, cut)
		if s > 0:
			p += min(s, beef) * h
	print(p)


t = int(input())
s = []
for i in range(t):
	s.append(0)
for i in range(t):
	z = list(map(int, input().split()))
	w = list(map(int, input().split()))
	b = z[0]
	p = z[1]
	f = z[2]
	h = w[0]
	c = w[1]
	if b > 1:
		if h >= c:
			while b > 1 and p > 0:
				s[i] += h
				b -= 2
				p -= 1
			if b > 1:
				while b > 1 and f > 0:
					s[i] += c
					b -= 2
					f -= 1
		else:
			while b > 1 and f > 0:
				s[i] += c
				b -= 2
				f -= 1
			if b > 1:
				while b > 1 and p > 0:
					s[i] += h
					b -= 2
					p -= 1
for i in s:
	print(i)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	k = b // 2
	if b // 2 > 0:
		if h <= c:
			m = 0
			n = 0
			for j in range(f):
				if k - (j + 1) < 0:
					k = k - j
					break
				if j == f - 1:
					k = k - (j + 1)
				m = j + 1
			for d in range(p):
				if k - (d + 1) < 0:
					break
				n = d + 1
			print(m * c + n * h, end=' ')
		else:
			m = 0
			n = 0
			for j in range(p):
				if k - (j + 1) < 0:
					k = k - j
					break
				if j == p - 1:
					k = k - (j + 1)
				n = j + 1
			for d in range(f):
				if k - (d + 1) < 0:
					break
				m = d + 1
			print(n * h + m * c, end=' ')
	else:
		print('0', end=' ')


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	(a, b) = map(int, input().split())
	c = 0
	if a > b:
		c += a * min(m, n // 2)
		n -= min(m, n // 2) * 2
		c += b * min(k, n // 2)
	elif a <= b:
		c += b * min(k, n // 2)
		n -= min(k, n // 2) * 2
		c += a * min(m, n // 2)
	print(c)


t = int(input())
while t != 0:
	(a, b, c) = map(int, input().split(' '))
	(d, e) = map(int, input().split(' '))
	w = 0
	f = a // 2
	if f > 0:
		if d >= e:
			if f >= b:
				x = b * d
				f = f - b
			else:
				x = f * d
				f = f - f
			if f > 0:
				if f >= c:
					x = x + c * e
				else:
					x = x + f * e
		else:
			if f >= c:
				x = c * e
				f = f - c
			else:
				x = f * e
				f = f - f
			if f > 0:
				if f >= b:
					x = x + b * d
				else:
					x = x + f * d
	else:
		print('0')
		w = 1
	if w == 0:
		print(x)
	t = t - 1


for _ in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	sum = 0
	if h > c:
		if b // 2 < p:
			sum = sum + b // 2 * h
		else:
			sum = sum + p * h
			b = b - p * 2
			if b // 2 < f:
				sum = sum + b // 2 * c
			else:
				sum = sum + f * c
	elif b // 2 < f:
		sum = sum + b // 2 * c
	else:
		sum = sum + f * c
		b = b - f * 2
		if b // 2 < p:
			sum = sum + b // 2 * h
		else:
			sum = sum + p * h
	print(sum)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
t = ii()
for _ in range(t):
	(b, p, fc) = f()
	(h, c) = f()
	sm = 0
	if h >= c:
		bun = min(b, 2 * p)
		sm += bun // 2 * h
		b -= bun
		sm += min(b, 2 * fc) // 2 * c
	else:
		bun = min(b, 2 * fc)
		sm += bun // 2 * c
		b -= bun
		sm += min(b, 2 * p) // 2 * h
	print(sm)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(a, b, c) = LI()
		(x, y) = LI()
		_ans = 0
		if x < y:
			_a = min(a // 2, c)
			a -= _a * 2
			c -= _a
			_ans += _a * y
			if a == 0:
				ans.append(_ans)
				continue
			_a = min(a // 2, b)
			a -= _a * 2
			b -= _a
			_ans += _a * x
		else:
			_a = min(a // 2, b)
			a -= _a * 2
			b -= _a
			_ans += _a * x
			if a == 0:
				ans.append(_ans)
				continue
			_a = min(a // 2, c)
			a -= _a * 2
			c -= _a
			_ans += _a * y
		ans.append(_ans)
	for x in ans:
		print(x)
main()


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(e, f) = map(int, input().split())
	total = a // 2
	sum = 0
	if e > f:
		if total > b:
			remain = total - b
			if remain > c:
				sum = b * e + c * f
			else:
				sum = b * e + remain * f
		else:
			sum = total * e
	elif total > c:
		remain = total - c
		if remain > b:
			sum = c * f + b * e
		else:
			sum = c * f + remain * e
	else:
		sum = total * f
	print(sum)


for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	cout = 0
	if h > c:
		while b >= 2:
			if p >= 1:
				cout = h + cout
				p = p - 1
			elif f >= 1:
				cout = c + cout
				f = f - 1
			b = b - 2
	elif h < c:
		while b >= 2:
			if f >= 1:
				cout = c + cout
				f = f - 1
			elif p >= 1:
				cout = h + cout
				p = p - 1
			b = b - 2
	else:
		cout = h * min(b // 2, p + f)
	print(cout)


for m in range(int(input())):
	bpf = list(map(int, input().split()))
	hc = list(map(int, input().split()))
	if bpf[0] // 2 >= bpf[1] + bpf[2]:
		print(bpf[1] * hc[0] + bpf[2] * hc[1])
	elif hc[0] > hc[1] and bpf[1] < bpf[0] // 2:
		print(bpf[1] * hc[0] + (bpf[0] // 2 - bpf[1]) * hc[1])
	elif hc[0] > hc[1] and bpf[0] // 2 <= bpf[1]:
		print(bpf[0] // 2 * hc[0])
	elif hc[1] >= hc[0] and bpf[2] < bpf[0] // 2:
		print(bpf[2] * hc[1] + (bpf[0] // 2 - bpf[2]) * hc[0])
	elif hc[1] >= hc[0] and bpf[2] >= bpf[0] // 2:
		print(hc[1] * (bpf[0] // 2))


def hitung(b, p, f, h, c, prof):
	if b <= 1:
		return prof
	else:
		if h >= c:
			if p > 0:
				return hitung(b - 2, p - 1, f, h, c, prof + h)
			elif f > 0:
				return hitung(b - 2, p, f - 1, h, c, prof + c)
			return prof
		if h <= c:
			if f > 0:
				return hitung(b - 2, p, f - 1, h, c, prof + c)
			if p > 0:
				return hitung(b - 2, p - 1, f, h, c, prof + h)
			return prof
t = int(input())
profit = []
for i in range(t):
	x = [int(i) for i in input().split()]
	y = [int(i) for i in input().split()]
	profit += [hitung(x[0], x[1], x[2], y[0], y[1], 0)]
for i in profit:
	print(i)


for _ in range(int(input())):
	(b, p, f) = list((int(a) for a in input().split()))
	(h, c) = list((int(a) for a in input().split()))
	if c > h:
		t = c
		c = h
		h = t
		t = p
		p = f
		f = t
	pr = 0
	hp = min(b // 2, p)
	b -= 2 * hp
	pr += hp * h
	hp = min(b // 2, f)
	pr += hp * c
	print(pr)


def burger_sales(ingredients, prices, t):
	for stock in range(0, int(t)):
		sandwiches = ingredients[stock][0] // 2
		if sandwiches > ingredients[stock][1] + ingredients[stock][2]:
			total = ingredients[stock][1] * prices[stock][0] + ingredients[stock][2] * prices[stock][1]
			print(total)
		elif prices[stock][0] > prices[stock][1]:
			if sandwiches <= ingredients[stock][1]:
				total = sandwiches * prices[stock][0]
				print(total)
			else:
				total = ingredients[stock][1] * prices[stock][0] + (sandwiches - ingredients[stock][1]) * prices[stock][1]
				print(total)
		elif sandwiches <= ingredients[stock][2]:
			total = sandwiches * prices[stock][1]
			print(total)
		else:
			total = ingredients[stock][2] * prices[stock][1] + (sandwiches - ingredients[stock][2]) * prices[stock][0]
			print(total)
t = input()
ingredients = []
prices = []
for T in range(0, int(t)):
	querie = input().split()
	ingredients.append([int(querie[0]), int(querie[1]), int(querie[2])])
	tags = input().split()
	prices.append([int(tags[0]), int(tags[1])])
burger_sales(ingredients, prices, t)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().rstrip().split())
	(h, c) = map(int, input().rstrip().split())
	(nb, cost) = (b // 2, 0)
	if h > c:
		if nb >= p:
			nb -= p
			cost = p * h
			cost += f * c if nb >= f else nb * c
		else:
			cost = nb * h
	elif c > h:
		if nb >= f:
			nb -= f
			cost = f * c
			cost += p * h if nb >= p else nb * h
		else:
			cost = nb * c
	elif p >= f:
		if nb >= p:
			nb -= p
			cost = p * h
			cost += f * c if nb >= f else nb * c
		else:
			cost = nb * h
	elif nb >= f:
		nb -= f
		cost = f * c
		cost += p * h if nb >= p else nb * h
	else:
		cost = nb * c
	print(cost)


n = int(input())
for i in range(n):
	m = list(map(int, input().split()))
	p = list(map(int, input().split()))
	bun = int(m[0] / 2)
	patty = m[1]
	chick = m[2]
	hp = p[0]
	cp = p[1]
	if hp > cp:
		h = min(bun, patty)
		bun = bun - h
		c = min(bun, chick)
		print(h * hp + c * cp)
	else:
		c = min(bun, chick)
		bun = bun - c
		h = min(bun, patty)
		print(h * hp + c * cp)


TestCases = int(input())
while TestCases > 0:
	maxProfit = 0

	def sellChicken(f):
		global Total_burger
		if Total_burger > 0 and f > 0:
			global maxProfit
			Total_burger = Total_burger - 1
			global c
			maxProfit = maxProfit + c
			sellChicken(f - 1)

	def sellHandBurger(p):
		global Total_burger
		if Total_burger > 0 and p > 0:
			global maxProfit
			Total_burger = Total_burger - 1
			global h
			maxProfit = maxProfit + h
			sellHandBurger(p - 1)
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	chickenSold = False
	HandburgerSold = False
	global Total_burger
	Total_burger = b // 2
	if max(h, c) == c:
		sellChicken(f)
		chickenSold = True
	else:
		sellHandBurger(p)
		HandburgerSold = True
	if chickenSold == True:
		sellHandBurger(p)
	else:
		sellChicken(f)
	print(maxProfit)
	TestCases = TestCases - 1


m = lambda : map(int, input().split())
for i in [0] * int(input()):
	(b, p, f) = m()
	b = b // 2
	(h, c) = m()
	if h > c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	print(min(f, b) * c + min(max(0, b - f), p) * h)


am = int(input())
for i in range(am):
	amArr = list(map(int, input().split()))
	pArr = list(map(int, input().split()))
	earn = 0
	if pArr[0] > pArr[1]:
		amSold = min(amArr[0] // 2, amArr[1])
		amSoldS = min((amArr[0] - amSold * 2) // 2, amArr[2])
		print(amSold * pArr[0] + amSoldS * pArr[1])
	else:
		amSold = min(amArr[0] // 2, amArr[2])
		amSoldS = min((amArr[0] - amSold * 2) // 2, amArr[1])
		print(amSold * pArr[1] + amSoldS * pArr[0])


t = int(input())
a = []
for i in range(t):
	x = input().split()
	x[0] = int(x[0])
	x[1] = int(x[1])
	x[2] = int(x[2])
	y = input().split()
	x.append(int(y[0]))
	x.append(int(y[1]))
	a.append(x)
for i in range(len(a)):
	s = 0
	if a[i][3] >= a[i][4]:
		s += a[i][3] * min(a[i][0] // 2, a[i][1])
		a[i][0] -= a[i][1] * 2
		f = 1
	else:
		s += a[i][4] * min(a[i][0] // 2, a[i][2])
		a[i][0] -= a[i][2] * 2
		f = 0
	if a[i][0] > 0:
		if f == 1:
			s += min(a[i][0] // 2, a[i][2]) * a[i][4]
		else:
			s += min(a[i][0] // 2, a[i][1]) * a[i][3]
	print(s)


def solve():
	data = list(map(int, input().split()))
	buns = data[0]
	buns = int(buns / 2)
	beef = data[1]
	chick = data[2]
	data2 = list(map(int, input().split()))
	cost_beef = data2[0]
	cost_chick = data2[1]
	total_cost = 0
	if cost_chick > cost_beef:
		if buns > chick:
			total_cost = total_cost + cost_chick * chick
			buns = buns - chick
		else:
			total_cost = total_cost + cost_chick * buns
			buns = 0
		if buns > beef:
			total_cost = total_cost + cost_beef * beef
			buns = buns - beef
		else:
			total_cost = total_cost + cost_beef * buns
	else:
		if buns > beef:
			total_cost = total_cost + cost_beef * beef
			buns = buns - beef
		else:
			total_cost = total_cost + cost_beef * buns
			buns = 0
		if buns > chick:
			total_cost = total_cost + cost_chick * chick
			buns = buns - chick
		else:
			total_cost = total_cost + cost_chick * buns
			buns = 0
	print(total_cost)
test_cases = int(input())
for x in range(test_cases):
	solve()


t = int(input())
for i in range(t):
	l = [int(i) for i in input().split()]
	p = [int(i) for i in input().split()]
	b = l.pop(0)
	profit = max(p) * min(l[p.index(max(p))], b // 2)
	b -= profit // max(p) * 2
	profit += min(p) * min(l[p.index(min(p))], b // 2)
	print(profit)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	half = b // 2
	z1 = min(p, f)
	z2 = max(p, f)
	if b >= 2:
		if half >= p + f:
			print(f * c + p * h)
		elif half >= p and half >= f and (half < p + f):
			x = half - p
			ans1 = p * h + x * c
			y = half - f
			ans2 = f * c + y * h
			print(max(ans1, ans2))
		elif half >= z1 and half <= z2:
			if p <= f:
				x = half - p
				ans1 = p * h + x * c
				ans2 = half * c
				print(max(ans1, ans2))
			else:
				x = half - f
				ans1 = x * h + f * c
				ans2 = half * h
				print(max(ans1, ans2))
		else:
			print(max(half * h, half * c))
	else:
		print(0)


import sys
for ss in sys.stdin:
	t = int(ss)
	for time in range(t):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		sum = 0
		if h >= c:
			while b >= 2 and p > 0:
				b -= 2
				p -= 1
				sum += h
			while b >= 2 and f > 0:
				b -= 2
				f -= 1
				sum += c
		else:
			while b >= 2 and f > 0:
				b -= 2
				f -= 1
				sum += c
			while b >= 2 and p > 0:
				b -= 2
				p -= 1
				sum += h
		print(sum)


t = int(input())
for i in range(t):
	c1 = 0
	c2 = 0
	(b, p, f) = input().strip().split(' ')
	(b, p, f) = [int(b), int(p), int(f)]
	(h, c) = input().strip().split(' ')
	(h, c) = [int(h), int(c)]
	if h > c:
		while b > 1 and p > 0:
			b -= 2
			p -= 1
			c1 += 1
		if b > 1:
			while b > 1 and f > 0:
				b -= 2
				f -= 1
				c2 += 1
		print(c * c2 + h * c1)
	else:
		while b > 1 and f > 0:
			b -= 2
			f -= 1
			c2 += 1
		if b > 1:
			while b > 1 and p > 0:
				b -= 2
				p -= 1
				c1 += 1
		print(c * c2 + h * c1)


def hotel(b, be, ch, bp, cp):
	nbuns = b // 2
	maxi = max(bp, cp)
	profit = 0
	bcnt = 0
	ccnt = 0
	if maxi == bp:
		while nbuns > 0 and bcnt < be:
			bcnt += 1
			nbuns -= 1
		profit += bcnt * bp
		while nbuns > 0 and ccnt < ch:
			ccnt += 1
			nbuns -= 1
		profit += ccnt * cp
	else:
		while nbuns > 0 and ccnt < ch:
			ccnt += 1
			nbuns -= 1
		profit += ccnt * cp
		while nbuns > 0 and bcnt < be:
			bcnt += 1
			nbuns -= 1
		profit += bcnt * bp
	print(profit)
q = int(input())
for i in range(q):
	(b, be, ch) = map(int, input().split())
	(bp, cp) = map(int, input().split())
	hotel(b, be, ch, bp, cp)


t = int(input())
for i in range(t):
	bpf = input().split()
	for i in range(len(bpf)):
		bpf[i] = int(bpf[i])
	(b, p, f) = bpf
	hc = input().split()
	for i in range(len(hc)):
		hc[i] = int(hc[i])
	(h, c) = hc
	b = b // 2
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	res = 0
	usep = p if p <= b else b
	res += usep * h
	b -= usep
	usef = f if f <= b else b
	res += usef * c
	b -= usef
	print(res)


t = int(input())
for case in range(t):
	count = 0
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	maxi = max(h, c)
	if maxi == h:
		price1 = h
		quantity1 = p
		quantity2 = f
		price2 = c
	else:
		price1 = c
		price2 = h
		quantity1 = f
		quantity2 = p
	while b > 1 and quantity1 > 0:
		quantity1 -= 1
		b -= 2
		count += price1
	while b > 1 and quantity2 > 0:
		quantity2 -= 1
		b -= 2
		count += price2
	print(count)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	r = list(map(int, input().split()))
	p = 0
	m = r.index(max(r))
	p += min(l[m + 1], l[0] // 2) * r[m]
	l[0] -= 2 * min(l[m + 1], l[0] // 2)
	if m == 0:
		p += min(l[2], l[0] // 2) * r[1]
	else:
		p += min(l[1], l[0] // 2) * r[0]
	print(p)


for _ in range(int(input())):
	(b, p, k) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	profit = 0
	if h > c:
		if b >= 2 * p:
			profit += p * h
			b -= 2 * p
			profit += min(b // 2, k) * c
		else:
			profit += h * (b // 2)
	elif b >= 2 * k:
		profit += k * c
		b -= 2 * k
		profit += min(b // 2, p) * h
	else:
		profit += c * (b // 2)
	print(profit)


t = int(input())
for qaq in range(t):
	(b, p, f) = input().split()
	(h, c) = input().split()
	(b, p, f, h, c) = (int(b), int(p), int(f), int(h), int(c))
	ans = 0
	if h > c:
		while b >= 2 and p > 0:
			p = p - 1
			b = b - 2
			ans = ans + h
		while b >= 2 and f > 0:
			f = f - 1
			b = b - 2
			ans = ans + c
	else:
		while b >= 2 and f > 0:
			f = f - 1
			b = b - 2
			ans = ans + c
		while b >= 2 and p > 0:
			p = p - 1
			b = b - 2
			ans = ans + h
	print(ans)


for i in range(int(input())):
	(b, p, c) = map(int, input().split())
	(h1, h2) = map(int, input().split())
	income = 0
	if h1 > h2:
		while b > 1 and p > 0:
			income = income + h1
			p = p - 1
			b = b - 2
		while b > 1 and c > 0:
			income = income + h2
			c = c - 1
			b = b - 2
	else:
		while b > 1 and c > 0:
			income = income + h2
			c = c - 1
			b = b - 2
		while b > 1 and p > 0:
			income = income + h1
			p = p - 1
			b = b - 2
	print(income)


def solve():
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	(hams, chicks) = (0, 0)
	if h >= c:
		hams = min(b // 2, p)
		b = b - 2 * hams
		chicks = min(b // 2, f)
	else:
		chicks = min(b // 2, f)
		b = b - 2 * chicks
		hams = min(b // 2, p)
	return hams * h + chicks * c
t = int(input())
for _ in range(t):
	print(solve())


def max_profit(b, p, f, h_price, c_price):
	ans = 0
	if c_price > h_price:
		while True:
			if b - 2 >= 0 and f - 1 >= 0:
				b -= 2
				f -= 1
				ans += c_price
			else:
				break
		while True:
			if b - 2 >= 0 and p - 1 >= 0:
				b -= 2
				p -= 1
				ans += h_price
			else:
				break
		return ans
	else:
		while True:
			if b - 2 >= 0 and p - 1 >= 0:
				b -= 2
				p -= 1
				ans += h_price
			else:
				break
		while True:
			if b - 2 >= 0 and f - 1 >= 0:
				ans += c_price
				b -= 2
				f -= 1
			else:
				break
		return ans
query = int(input())
for _ in range(query):
	(b, p, f) = map(int, input().split())
	(h_price, c_price) = map(int, input().split())
	print(max_profit(b, p, f, h_price, c_price))


q = int(input())
for Q in range(q):
	(b, p, f) = tuple(map(int, input().split()))
	(h, c) = tuple(map(int, input().split()))
	cost = 0
	if h > c:
		k = min(b // 2, p)
		cost = k * h
		b -= k * 2
		p -= k
		if b >= 2:
			cost += min(b // 2, f) * c
	else:
		k = min(b // 2, f)
		cost += k * c
		b -= k * 2
		f -= k
		if b >= 2:
			cost += min(b // 2, p) * h
	print(cost)


t = int(input())
b = []
p = []
f = []
h = []
c = []
for i in range(t):
	line = str(input())
	a = []
	a = line.split(' ')
	b.append(int(a[0]))
	p.append(int(a[1]))
	f.append(int(a[2]))
	a.clear()
	line = str(input())
	a = line.split(' ')
	h.append(int(a[0]))
	c.append(int(a[1]))
for i in range(t):
	maxprice = 0
	sumary = 0
	count = 0
	while b[i] > 1:
		if h[i] > c[i]:
			if p[i] == 0:
				break
			b[i] -= 2
			p[i] -= 1
			count += h[i]
		elif h[i] == c[i]:
			if p[i] == 0:
				if f[i] == 0:
					break
				b[i] -= 2
				f[i] -= 1
				count += c[i]
				continue
			b[i] -= 2
			p[i] -= 1
			count += h[i]
		else:
			if f[i] == 0:
				break
			b[i] -= 2
			f[i] -= 1
			count += c[i]
	while b[i] > 1:
		if h[i] < c[i]:
			if p[i] == 0:
				break
			b[i] -= 2
			p[i] -= 1
			count += h[i]
		else:
			if f[i] == 0:
				break
			b[i] -= 2
			f[i] -= 1
			count += c[i]
	print(count)


q = int(input())
for i in range(q):
	(w, e, r) = map(int, input().split())
	(t, y) = map(int, input().split())
	u = w // 2
	if t > y:
		a = min(u, e)
		print(a * t + min(u - a, r) * y)
	else:
		a = min(u, r)
		print(a * y + min(u - a, e) * t)


t = int(input())
while t != 0:
	t = t - 1
	(buns, patty, cutlet) = map(int, input().split())
	(hamburger, chichenburger) = map(int, input().split())
	maxp = 0
	minp = 0
	maxn = 0
	minn = 0
	if hamburger > chichenburger:
		maxp = hamburger
		maxn = patty
		minp = chichenburger
		minn = cutlet
	else:
		maxp = chichenburger
		maxn = cutlet
		minp = hamburger
		minn = patty
	totalprofit = 0
	if buns // 2 <= maxn:
		totalprofit = maxp * (buns // 2)
	elif buns // 2 - maxn <= minn:
		totalprofit = maxp * maxn + (buns // 2 - maxn) * minp
	else:
		totalprofit = maxp * maxn + minn * minp
	print(totalprofit)


a = int(input())
for i in range(a):
	(n, m, l) = [int(j) for j in input().split()]
	(b, c) = [int(j) for j in input().split()]
	if b >= c:
		if n // 2 <= m:
			print(n // 2 * b)
		else:
			print(min(l, n // 2 - m) * c + b * m)
	elif n // 2 <= l:
		print(n // 2 * c)
	else:
		print(min(m, n // 2 - l) * b + c * l)


in1 = int(input())
for i in range(in1):
	pro = 0
	in2 = input().split()
	in3 = input().split()
	in2 = list(map(int, in2))
	in3 = list(map(int, in3))
	b = int(in2[0])
	ma = max(in3)
	mi = min(in3)
	ind1 = in3.index(ma)
	ind2 = in3.index(mi)
	if b >= 2 * in2[ind1 + 1]:
		pro = in2[ind1 + 1] * ma
		b = b - 2 * in2[ind1 + 1]
		if b >= 2 * in2[ind2 + 1]:
			pro = pro + in2[ind2 + 1] * mi
		else:
			pro = pro + mi * (b // 2)
	else:
		pro = ma * (b // 2)
	print(pro)


t = int(input())
while t >= 1:
	t = t - 1
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	f = 0
	if d < e:
		(b, c, d, e) = (c, b, e, d)
	while a >= 2 and (b >= 1 or c >= 1):
		if b >= 1:
			(a, b, f) = (a - 2, b - 1, f + d)
		else:
			(a, c, f) = (a - 2, c - 1, f + e)
	print(f)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	(maxcena, mincena) = (max(h, c), min(h, c))
	if maxcena == h:
		summ = min(b, p) * maxcena + max(0, min(b - min(b, p), f)) * mincena
	else:
		summ = min(b, f) * maxcena + max(0, min(b - min(b, f), p)) * mincena
	print(summ)


R = lambda : map(int, input().split())
for _ in range(int(input())):
	(b, p, q) = R()
	(h, c) = R()
	if h > c:
		l = min(b // 2, p)
		b -= 2 * l
		res = l * h
		if b > 0:
			res += min(b // 2, q) * c
		print(res)
	else:
		l = min(b // 2, q)
		b -= 2 * l
		res = l * c
		if b > 0:
			res += min(b // 2, p) * h
		print(res)


tc = int(input())
for _ in range(tc):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	maxham = min(b // 2, p)
	remham = min((b - maxham * 2) // 2, f)
	maxchick = min(b // 2, f)
	remchick = min((b - maxchick * 2) // 2, p)
	print(max(maxham * h + remham * c, maxchick * c + remchick * h))


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	hamb = chic = 0
	if b < 2:
		print(0)
	elif h > c:
		hamb = min(b // 2, p)
		if b - hamb * 2 >= 2:
			b -= hamb * 2
			chic = min(b // 2, f)
		print(hamb * h + chic * c)
	else:
		chic = min(b // 2, f)
		if b - chic * 2 >= 2:
			b -= chic * 2
			hamb = min(b // 2, p)
		print(hamb * h + chic * c)


q = int(input())
for i in range(q):
	(bun, beef, chick) = map(int, input().split())
	(beefp, chickp) = map(int, input().split())
	bune = bun // 2
	if beefp > chickp:
		if bune >= beef + chick:
			pro = beef * beefp + chick * chickp
		elif bune >= beef:
			pro = beef * beefp + (bune - beef) * chickp
		else:
			pro = bune * beefp
	elif bune >= beef + chick:
		pro = beef * beefp + chick * chickp
	elif bune >= chick:
		pro = chick * chickp + (bune - chick) * beefp
	else:
		pro = bune * chickp
	print(int(pro))


t = int(input())
for case in range(t):
	profit = 0
	(buns, beef_patties, cutlets) = [int(b) for b in input().split()]
	(beef_price, cutlet_price) = [int(h) for h in input().split()]
	possible_burgers = buns // 2
	if beef_price >= cutlet_price:
		if beef_patties > possible_burgers:
			beef_patties = possible_burgers
		profit += beef_patties * beef_price
		possible_burgers -= beef_patties
		if cutlets > possible_burgers:
			cutlets = possible_burgers
		profit += cutlets * cutlet_price
		possible_burgers -= cutlets
	elif cutlet_price >= beef_price:
		if cutlets > possible_burgers:
			cutlets = possible_burgers
		profit += cutlets * cutlet_price
		possible_burgers -= cutlets
		if beef_patties > possible_burgers:
			beef_patties = possible_burgers
		profit += beef_patties * beef_price
		possible_burgers -= beef_patties
	print(profit)


T = int(input())
for case in range(T):
	(b, p, f) = map(int, input().strip().split())
	(h, c) = map(int, input().strip().split())
	if h > c:
		t = min(b // 2, p)
		print(t * h + min((b - t * 2) // 2, f) * c)
	else:
		t = min(b // 2, f)
		print(t * c + min((b - t * 2) // 2, p) * h)


t = int(input())
for i in range(1, t + 1, 1):
	sum = 0
	m = 0
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	a = a // 2
	if d < e:
		(d, e) = (e, d)
		(b, c) = (c, b)
	m = min(a, b)
	a = a - m
	b = b - m
	sum += d * m
	m = min(a, c)
	a = a - m
	c = c - m
	sum += e * m
	print(sum)


t = int(input())
for _ in range(t):
	(b, p, f) = (int(i) for i in input().split())
	(h, c) = (int(i) for i in input().split())
	cnt = 0
	if h < c:
		(p, f) = (f, p)
		(h, c) = (c, h)
	used_bulks = min(b - b % 2, p * 2)
	cnt += h * used_bulks // 2
	b -= used_bulks
	used_bulks = min(b - b % 2, f * 2)
	cnt += c * used_bulks // 2
	print(cnt)


n = int(input())
s = []
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	if p >= b:
		s.append(b * h)
	else:
		s.append(p * h + min(b - p, f) * c)
	if f >= b:
		s.append(b * c)
	else:
		s.append(f * c + min(b - f, p) * h)
	print(max(s))
	s = []


N = int(input())
for i in range(0, N):
	Data0 = list(map(int, input().split()))
	Data1 = list(map(int, input().split()))
	numB = Data0[0] // 2
	numP = Data0[1]
	numF = Data0[2]
	ans = 0
	if Data1[0] > Data1[1]:
		t0 = min(numB, numP)
		numB -= t0
		t1 = min(numB, numF)
		ans = t0 * Data1[0] + t1 * Data1[1]
	else:
		t1 = min(numB, numF)
		numB -= t1
		t0 = min(numB, numP)
		ans = t0 * Data1[0] + t1 * Data1[1]
	print(ans)


q = int(input())
for _ in range(q):
	(a, b, c) = map(int, input().split())
	(x, y) = map(int, input().split())
	res = -1
	xx = min(a // 2, b)
	res = x * xx
	res += y * min(c, (a - 2 * xx) // 2)
	xx = min(a // 2, c)
	res2 = y * xx
	res2 += x * min(b, (a - 2 * xx) // 2)
	print(max(res, res2))


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(b, p, f) = map(int, sys.stdin.readline().split(' '))
	(h, c) = map(int, sys.stdin.readline().split(' '))
	b = b // 2
	ans = 0
	if h >= c:
		val = min(b, p)
		ans += val * h
		b -= val
		val = min(b, f)
		ans += val * c
	else:
		val = min(b, f)
		ans += val * c
		b -= val
		val = min(b, p)
		ans += val * h
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


a = int(input())
for r in range(0, a):
	sells = 0
	b = input()
	c = b.split()
	d = list(map(int, c))
	b1 = input()
	c1 = b1.split()
	d1 = list(map(int, c1))
	if d1[1] >= d1[0]:
		for i in range(0, d[2]):
			if d[0] >= 2:
				sells = sells + d1[1]
				d[0] = d[0] - 2
		for i in range(0, d[1]):
			if d[0] >= 2:
				sells = sells + d1[0]
				d[0] = d[0] - 2
	if d1[0] > d1[1]:
		for i in range(0, d[1]):
			if d[0] >= 2:
				sells = sells + d1[0]
				d[0] = d[0] - 2
		for i in range(0, d[2]):
			if d[0] >= 2:
				sells = sells + d1[1]
				d[0] = d[0] - 2
	print(sells)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	profit = 0
	while b:
		if p != 0 and f != 0:
			if h >= c and b >= 2:
				profit += h
				p -= 1
				b -= 2
			elif h < c and b >= 2:
				profit += c
				f -= 1
				b -= 2
			else:
				break
		elif p == 0 and f != 0:
			if b >= 2:
				profit += c
				f -= 1
				b -= 2
			else:
				break
		elif p != 0 and f == 0:
			if b >= 2:
				profit += h
				p -= 1
				b -= 2
			else:
				break
		else:
			break
	print(profit)


num_cases = int(input())
for case in range(1, num_cases + 1):
	(b, p, f) = [int(x) for x in input().split(' ')]
	(h, c) = [int(x) for x in input().split(' ')]
	ans = 0
	if c < h:
		while b >= 2 and p >= 1:
			ans += h
			b -= 2
			p -= 1
		while b >= 2 and f >= 1:
			ans += c
			b -= 2
			f -= 1
	else:
		while b >= 2 and f >= 1:
			ans += c
			b -= 2
			f -= 1
		while b >= 2 and p >= 1:
			ans += h
			b -= 2
			p -= 1
	print(ans)


n = int(input())
l = 0
o = 0
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	z = b // 2
	if z >= p + f:
		print(p * h + f * c)
	elif z > f or z > p:
		if z >= p and z < f:
			s1s = p * h + (z - p) * c
			s2s = z * c
			print(max(s1s, s2s))
		elif z >= f and z < p:
			s1s = f * c + (z - f) * h
			s2s = z * h
			print(max(s1s, s2s))
		else:
			s1s = p * h + (z - p) * c
			s2s = f * c + (z - f) * h
			print(max(s1s, s2s))
	else:
		print(max(z * h, z * c))


t = int(input())
while t:
	t = t - 1
	ans = 0
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	buns = b // 2
	if buns >= p + f:
		ans = p * h + f * c
	elif buns >= 1:
		if c >= h:
			ans = f * c + (buns - f) * h
			if buns < f:
				ans = buns * c
		else:
			ans = p * h + (buns - p) * c
			if buns < p:
				ans = buns * h
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	sum = 0
	(b, p, f) = input().split()
	(h, c) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	h = int(h)
	c = int(c)
	n = b // 2
	if h > c:
		if p >= n:
			sum = h * n
		elif n - p <= f:
			sum = p * h + (n - p) * c
		else:
			sum = p * h + f * c
	if h <= c:
		if f >= n:
			sum = c * n
		elif n - f <= p:
			sum = f * c + (n - f) * h
		else:
			sum = f * c + p * h
	print(sum)


import time

def getMaximumBuns(firstL, secondL):
	buns = firstL[0]
	beefB = firstL[1]
	chickenB = firstL[2]
	priceBeefB = secondL[0]
	priceChickenB = secondL[1]
	totalPrice = 0
	maxPrice = max(priceChickenB, priceBeefB)
	if maxPrice == priceBeefB:
		qtyBeef = calculateBurguers(buns, beefB)
		totalPrice += qtyBeef * priceBeefB
		beefB -= qtyBeef
		buns -= qtyBeef * 2
		qtyChicken = calculateBurguers(buns, chickenB)
		totalPrice += qtyChicken * priceChickenB
		chickenB -= qtyChicken
		buns -= qtyChicken * 2
	elif maxPrice == priceChickenB:
		qtyChicken = calculateBurguers(buns, chickenB)
		totalPrice += qtyChicken * priceChickenB
		chickenB -= qtyChicken
		buns -= qtyChicken * 2
		qtyBeef = calculateBurguers(buns, beefB)
		totalPrice += qtyBeef * priceBeefB
		beefB -= qtyBeef
		buns -= qtyBeef * 2
	return totalPrice

def calculateBurguers(buns, burguers):
	maxBreads = int(buns / 2)
	if maxBreads == burguers:
		totalQty = maxBreads
	elif maxBreads < burguers:
		totalQty = maxBreads
	else:
		totalQty = burguers
	return totalQty

def solve():
	queries = int(input())
	fsLines = []
	for x in range(queries):
		fLine = [int(x) for x in input().split()]
		sLine = [int(x) for x in input().split()]
		res = getMaximumBuns(fLine, sLine)
		fsLines.append(res)
		print(res)
solve()


t = int(input())
while t:
	t -= 1
	(b, p, f) = map(int, input().split(' '))
	(h, c) = map(int, input().split(' '))
	sum = 0
	if h < c:
		x = h
		h = c
		c = x
		x = p
		p = f
		f = x
	b = b // 2
	sum = sum + h * min(b, p)
	b = b - min(b, p)
	sum = sum + c * min(b, f)
	print(sum)


prezzi = {}
cibo = []
cont = 0
a = input()
a = int(a) * 2
indice = -1
prezzo_totale = 0
for x in range(a):
	if cont == 0:
		k = input().split()
		lb = int(k[0])
		lp = int(k[1])
		lf = int(k[2])
		cont += 1
		cibo.append((lb, lp, lf))
	else:
		indice += 1
		k = input().split()
		cont -= 1
		h = int(k[0])
		c = int(k[1])
		if h >= c:
			prezzi[indice] = ['h', h, 'c', c]
		else:
			prezzi[indice] = ['c', c, 'h', h]
for x in prezzi:
	a = prezzi[x]
	if a[0] == 'h':
		b = cibo[x][0]
		r = cibo[x][1]
		for y in range(cibo[x][0]):
			b = b - 2
			r = r - 1
			if b > -1 and r > -1:
				prezzo_totale += prezzi[x][1]
			else:
				b += 2
		f = cibo[x][2]
		for y in range(cibo[x][0]):
			b -= 2
			f -= 1
			if f > -1 and b > -1:
				prezzo_totale += prezzi[x][3]
		print(prezzo_totale)
		prezzo_totale = 0
	elif a[0] == 'c':
		b = cibo[x][0]
		r = cibo[x][2]
		for y in range(cibo[x][0]):
			b = b - 2
			r = r - 1
			if b > -1 and r > -1:
				prezzo_totale += prezzi[x][1]
			else:
				b += 2
		f = cibo[x][1]
		for y in range(cibo[x][0]):
			b -= 2
			f -= 1
			if f > -1 and b > -1:
				prezzo_totale += prezzi[x][3]
		print(prezzo_totale)
		prezzo_totale = 0


import os
res = list()
count = int(input())
for a in range(0, count):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	for i in range(0, b + 1, 2):
		if ans <= max([0, h * min(i // 2, p) + c * min((b - i) // 2, f)]):
			ans = max([0, h * min(i // 2, p) + c * min((b - i) // 2, f)])
	res.append(ans)
for i in range(0, count):
	print(res[i])


for T in range(int(input())):
	(b, p, f) = [int(i) for i in input().strip().split()]
	(h, c) = [int(i) for i in input().strip().split()]
	ans = 0
	if h > c:
		x = int(min(p, int(b / 2)))
		ans += x * h
		b -= 2 * x
		if b > 1:
			y = int(min(f, int(b / 2)))
			ans += y * c
	else:
		x = int(min(f, int(b / 2)))
		ans += x * c
		b -= 2 * x
		if b > 1:
			y = int(min(p, int(b / 2)))
			ans += y * h
	print(ans)


def venderBurguers(pB, B, pC, C, burguers):
	tot = 0
	for i in range(burguers):
		if C != 0:
			tot += pC
			C -= 1
		elif B != 0:
			tot += pB
			B -= 1
	print(tot)
t = int(input())
for i in range(t):
	(paes, bife, galinha) = map(int, input().split())
	(b, g) = map(int, input().split())
	paes = paes // 2
	if b > g:
		venderBurguers(g, galinha, b, bife, paes)
	else:
		venderBurguers(b, bife, g, galinha, paes)


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : map(int, rd().strip().split())
t = int(rd())
while t:
	(b, p, f) = rrd()
	(h, c) = rrd()
	ans = 0
	if h > c:
		ct = min(b // 2, p)
		ans += h * ct
		b -= ct * 2
		p -= ct
		ans += c * min(b // 2, f)
	else:
		ct = min(b // 2, f)
		ans += c * ct
		b -= ct * 2
		f -= ct
		ans += h * min(b // 2, p)
	print(ans)
	t -= 1


def profit(b, p, f, h, c):
	pr = 0
	if h > c:
		while b > 1 and p >= 1:
			b -= 2
			p -= 1
			pr += h
		while b > 1 and f >= 1:
			b -= 2
			f -= 1
			pr += c
	else:
		while b > 1 and f >= 1:
			b -= 2
			f -= 1
			pr += c
		while b > 1 and p >= 1:
			b -= 2
			p -= 1
			pr += h
	return pr
a = []
for _ in range(int(input())):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	a.append(profit(b, p, f, h, c))
print(*a, sep='\n')


a = int(input())
for _ in range(a):
	(b, c, d) = map(int, input().split(' '))
	(f, e) = map(int, input().split(' '))
	s = 0
	if b <= 1:
		print(0)
		continue
	elif e > f:
		while b >= 2 and d > 0:
			s = s + e
			d = d - 1
			b = b - 2
		while b >= 2 and c > 0:
			s = s + f
			b = b - 2
			c = c - 1
	else:
		while b >= 2 and c > 0:
			s = s + f
			b = b - 2
			c = c - 1
		while b >= 2 and d > 0:
			b = b - 2
			s = s + e
			d = d - 1
	print(s)


t = int(input())
for i in range(t):
	q = input().split()
	c = input().split()
	(b, p, f) = (int(q[0]), int(q[1]), int(q[2]))
	(h, c) = (int(c[0]), int(c[1]))
	m = 0
	b = int(b / 2)
	if c > h:
		if b > f:
			m += f * c
			b = b - f
			if b < p:
				m += b * h
			else:
				m += p * h
		else:
			m += b * c
	elif b > p:
		m += p * h
		b = b - p
		if b < f:
			m += b * c
		else:
			m += f * c
	else:
		m += b * h
	print(m)


t = int(input())
for i in range(0, t):
	(b, bp, cc) = list(map(int, input().split()))
	(p1, p2) = list(map(int, input().split()))
	m = max(p1, p2)
	c1 = c2 = 0
	if m == p1:
		ans1 = min(b // 2, bp)
		b = b - ans1 * 2
		c1 = c1 + ans1 * p1
		if b > 1:
			ans2 = min(b // 2, cc)
			c2 = c2 + ans2 * p2
		print(c1 + c2)
	elif m == p2:
		ans1 = min(b // 2, cc)
		b = b - ans1 * 2
		c1 = c1 + ans1 * p2
		if b > 1:
			ans2 = min(b // 2, bp)
			c2 = c2 + ans2 * p1
		print(c1 + c2)


n = int(input())
for i in range(n):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	(d, e) = input().split()
	d = int(d)
	e = int(e)
	if max(d, e) == e:
		h = min(a // 2, c)
		s = h * e
		a = a - 2 * h
		m = min(a // 2, b)
		s = s + m * d
	else:
		h = min(a // 2, b)
		s = h * d
		a = a - 2 * h
		m = min(a // 2, c)
		s = s + m * e
	print(s)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	p1 = 2 * p
	f1 = 2 * f
	if p1 + f1 <= b:
		print(p * h + f * c)
	else:
		if h >= c:
			k = 0
			l = 0
			for i in range(p):
				if b > 1:
					b = b - 2
					k = k + 1
				else:
					break
			l = l + k * h
			r = 0
			for i in range(f):
				if b > 1:
					b = b - 2
					r = r + 1
				else:
					break
			l = l + r * c
			print(l)
		if h < c:
			k = 0
			l = 0
			for i in range(f):
				if b > 1:
					b = b - 2
					k = k + 1
				else:
					break
			l = l + k * c
			r = 0
			for i in range(p):
				if b > 1:
					b = b - 2
					r = r + 1
				else:
					break
			l = l + r * h
			print(l)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	burgers = b // 2
	if h >= c:
		x = min(p, burgers) * h
		burgers = max(0, burgers - p)
		y = min(burgers, f) * c
		print(x + y)
	else:
		x = min(f, burgers) * c
		burgers = max(0, burgers - f)
		y = min(burgers, p) * h
		print(x + y)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	gain = 0
	while b > 1 and (p > 0 or f > 0):
		while p > 0 and b > 1:
			if h > c or f == 0:
				gain = gain + h
				b = b - 2
				p = p - 1
			else:
				break
		while f > 0 and b > 1:
			if h <= c or p == 0:
				gain = gain + c
				b = b - 2
				f = f - 1
			else:
				break
	print(gain)


def main():

	def solve():
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		if h > c:
			hb = min(b // 2, p)
			cb = max(0, min(f, b // 2 - p))
		else:
			cb = min(b // 2, f)
			hb = max(0, min(p, b // 2 - f))
		print(h * hb + c * cb)
	q = int(input())
	for _ in range(q):
		solve()
main()


def calc():
	print()

def main():
	for _ in range(int(input())):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		profit: int = 0
		if c < h:
			while b >= 2 and p != 0:
				b -= 2
				p -= 1
				profit += h
			while b >= 2 and f != 0:
				b -= 2
				f -= 1
				profit += c
		else:
			while b >= 2 and f != 0:
				b -= 2
				f -= 1
				profit += c
			while b >= 2 and p != 0:
				b -= 2
				p -= 1
				profit += h
		print(profit)
main()


n = int(input())
for i in range(n):
	(b, p, f) = [int(_) for _ in input().split()]
	(h, c) = [int(_) for _ in input().split()]
	profit = 0
	if c > h:
		(h, c) = (c, h)
		(p, f) = (f, p)
	if p * 2 <= b:
		profit += p * h
		b -= p * 2
	else:
		profit += b // 2 * h
		b -= b // 2 * 2
	if f * 2 <= b:
		profit += f * c
		b -= f * 2
	else:
		profit += b // 2 * c
		b -= b // 2 * 2
	print(profit)


n = int(input())
k = []
l = []
for i in range(n):
	b = input().split()
	c = input().split()
	for i in range(len(b)):
		b[i] = int(b[i])
	for i in range(len(c)):
		c[i] = int(c[i])
	k.append(b)
	l.append(c)
for i in range(n):
	TB = k[i][0] // 2
	if TB >= k[i][1] + k[i][2]:
		profit = k[i][1] * l[i][0] + k[i][2] * l[i][1]
	if TB < k[i][1] + k[i][2]:
		if l[i][0] > l[i][1]:
			if TB - k[i][1] > 0:
				profit = k[i][1] * l[i][0] + (TB - k[i][1]) * l[i][1]
			if TB - k[i][1] <= 0:
				profit = TB * l[i][0]
		if l[i][0] < l[i][1]:
			if TB - k[i][2] > 0:
				profit = k[i][2] * l[i][1] + (TB - k[i][2]) * l[i][0]
			if TB - k[i][2] <= 0:
				profit = TB * l[i][1]
		if l[i][0] == l[i][1]:
			profit = TB * l[i][0]
	print(profit)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	beef = min(b // 2, p)
	chicken = min(b // 2, f)
	if h > c:
		ans += beef * h
		b -= 2 * beef
		ans += min(b // 2, f) * c
	else:
		ans += chicken * c
		b -= 2 * chicken
		ans += min(b // 2, p) * h
	print(ans)


t = int(input())
for itr in range(t):
	(buns, beef, chicken) = map(int, input().split(' '))
	(beef_price, chicken_price) = map(int, input().split(' '))
	mx = 0
	buns = buns // 2
	for i in range(buns + 1):
		mx = max(mx, min(i, beef) * beef_price + min(buns - i, chicken) * chicken_price)
	print(mx)


t = int(input())
profs = []
for i in range(t):
	prof = 0
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	for i in range(b // 2):
		if h > c:
			if p >= 1:
				prof += h
				p -= 1
			elif f >= 1:
				prof += c
				f -= 1
		elif f >= 1:
			prof += c
			f -= 1
		elif p >= 1:
			prof += h
			p -= 1
	profs.append(prof)
for pr in profs:
	print(pr)


t = int(input())

def solve():
	(a, b, c) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	mx = max(min(a // 2, b) * c1 + min((a - min(a // 2, b) * 2) // 2, c) * c2, min(a // 2, c) * c2 + min((a - min(a // 2, c) * 2) // 2, b) * c1)
	print(mx)
for i in range(t):
	solve()


import sys, math, queue, collections
MOD = 10 ** 9 + 7
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h > c:
		x = min(b // 2, p)
		b -= 2 * x
		y = min(b // 2, f)
	else:
		y = min(b // 2, f)
		b -= 2 * y
		x = min(b // 2, p)
	print(h * x + c * y)


q = int(input())
i = 1
while i <= q:
	(b, p, f) = input().split()
	b = int(b)
	p = int(p)
	f = int(f)
	(h, c) = input().split()
	h = int(h)
	c = int(c)
	b1 = int(b) // 2
	pro = 0
	nh = 0
	nc = 0
	i += 1
	if h > c:
		while p != 0 and b1 != 0:
			b1 -= 1
			p -= 1
			nh += 1
		while f != 0 and b1 != 0:
			b1 -= 1
			f -= 1
			nc += 1
	elif c > h:
		while f != 0 and b1 != 0:
			b1 -= 1
			f -= 1
			nc += 1
		while p != 0 and b1 != 0:
			b1 -= 1
			p -= 1
			nh += 1
	elif p > f:
		while p != 0 and b1 != 0:
			b1 -= 1
			p -= 1
			nh += 1
		while f != 0 and b1 != 0:
			b1 -= 1
			f -= 1
			nc += 1
	else:
		while f != 0 and b1 != 0:
			b1 -= 1
			f -= 1
			nc += 1
		while p != 0 and b1 != 0:
			b1 -= 1
			p -= 1
			nh += 1
	pro = nh * h + nc * c
	print(pro)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	mx = 0
	for x in range(0, p + 1):
		if 2 * x > b:
			continue
		y = min(f, max(0, (b - 2 * x) // 2))
		mx = max(mx, h * x + c * y)
	print(mx)


def mp():
	return map(int, input().split())
q = int(input())
for qq in range(q):
	(b, p, f) = mp()
	(h, c) = mp()
	ans = 0
	while b > 1 and p + f > 0:
		if h > c:
			if p > 0:
				ans += h
				p -= 1
				b -= 2
			else:
				ans += c
				f -= 1
				b -= 2
		elif f > 0:
			ans += c
			f -= 1
			b -= 2
		else:
			ans += h
			p -= 1
			b -= 2
	print(ans)


import sys

def get_max_burgers(nubs, beefs, chickens, beefPrice, chickenPrice):
	if nubs >= 2 and beefs >= 1:
		return beefPrice + get_max_burgers(nubs - 2, beefs - 1, chickens, beefPrice, chickenPrice)
	elif nubs >= 2 and chickens >= 1:
		return chickenPrice + get_max_burgers(nubs - 2, beefs, chickens - 1, beefPrice, chickenPrice)
	else:
		return 0

def get_max_profit(nubs, beefs, chickens, beefPrice, chickenPrice):
	profit = 0
	if beefPrice > chickenPrice:
		profit += get_max_burgers(nubs, beefs, chickens, beefPrice, chickenPrice)
	else:
		profit += get_max_burgers(nubs, chickens, beefs, chickenPrice, beefPrice)
	return profit
lines = int(sys.stdin.readline())
for i in range(lines):
	parts = sys.stdin.readline().split(' ')
	nubs = int(parts[0])
	beefs = int(parts[1])
	chickens = int(parts[2])
	prices = sys.stdin.readline().split(' ')
	beefPrice = int(prices[0])
	chickenPrice = int(prices[1])
	maxProfit = get_max_profit(nubs, beefs, chickens, beefPrice, chickenPrice)
	print(maxProfit)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	a = a // 2
	total = 0
	if a > 0:
		if d > e:
			total += min(b, a) * d
			a = a - b
			if a > 0:
				total += min(c, a) * e
		else:
			total += min(c, a) * e
			a = a - c
			if a > 0:
				total += min(b, a) * d
	print(total)


a = int(input())
ans = []
for i in range(0, a):
	b = input()
	c = [int(x) for x in b.split()]
	d = input()
	e = [int(x) for x in d.split()]
	m = 0
	if e[0] <= e[1]:
		chick = c[0] // 2
		if chick > c[2]:
			chick = c[2]
		m = m + chick * e[1]
		c[0] -= chick * 2
		beef = c[0] // 2
		if beef > c[1]:
			beef = c[1]
		m = m + beef * e[0]
	else:
		beef = c[0] // 2
		if beef > c[1]:
			beef = c[1]
		m = m + beef * e[0]
		c[0] -= beef * 2
		chick = c[0] // 2
		if chick > c[2]:
			chick = c[2]
		m = m + chick * e[1]
	ans.append(m)
for j in range(0, a):
	print(ans[j])


for _ in range(int(input())):
	(b, p, f) = [int(i) for i in input().split()]
	(h, c) = [int(i) for i in input().split()]
	m = 0
	while b > 1:
		if h > c:
			for i in range(p):
				if b > 1:
					m += h
					b -= 2
				else:
					break
			for i in range(f):
				if b > 1:
					m += c
					b -= 2
				else:
					break
			break
		else:
			for i in range(f):
				if b > 1:
					m += c
					b -= 2
				else:
					break
			for i in range(p):
				if b > 1:
					m += h
					b -= 2
				else:
					break
			break
	print(m)


t = int(input())
while t != 0:
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	if p + f < b // 2:
		print(h * p + c * f)
	else:
		max = 0
		sum = b // 2
		start_x = min(p, sum)
		for x in range(start_x, -1, -1):
			mild = (h - c) * x + c * sum
			if sum - x <= f:
				if max < mild:
					max = mild
		print(max)
	t = t - 1


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	buns = b // 2
	res = 0
	if c >= h:
		if buns > f:
			res += f * c
			diff = buns - f
			if diff > p:
				res += p * h
			else:
				res += diff * h
		else:
			res += buns * c
	elif buns > p:
		res += p * h
		diff = buns - p
		if diff > f:
			res += f * c
		else:
			res += diff * c
	else:
		res += buns * h
	print(res)


import sys
t = int(input())
for _ in range(t):
	(b, p, f) = map(int, sys.stdin.readline().split())
	(h, c) = map(int, sys.stdin.readline().split())
	if h >= c:
		num_h = min(b // 2, p)
		num_c = min((b - 2 * num_h) // 2, f)
		print(num_h * h + num_c * c)
	else:
		num_c = min(b // 2, f)
		num_h = min((b - 2 * num_c) // 2, p)
		print(num_h * h + num_c * c)


import sys
t = int(sys.stdin.readline())
for i in range(0, t):
	(b, p, f) = list(map(int, sys.stdin.readline().strip().split()))
	(h, c) = list(map(int, sys.stdin.readline().strip().split()))
	if c > h:
		(c, h, p, f) = (h, c, f, p)
	ans = 0
	x = min([b // 2, p])
	p = p - x
	b = b - 2 * x
	ans = ans + h * x
	x = min([b // 2, f])
	f = f - x
	b = b - 2 * x
	ans = ans + c * x
	print(ans)


for _ in range(int(input())):
	(b, p, f) = [int(x) for x in input().split()]
	(h, c) = [int(x) for x in input().split()]
	buns = b / 2
	if h > c:
		profit = min(int(buns), p) * h
		buns = buns - p
		if buns > 0:
			profit = profit + min(int(buns), f) * c
	else:
		profit = min(int(buns), f) * c
		buns = buns - f
		if buns > 0:
			profit = profit + min(int(buns), p) * h
	print(profit)


queries = int(input())
for i in range(queries):
	lucro = 0
	(pao, carne, frango) = map(int, input().split())
	(carnePreco, frangoPreco) = map(int, input().split())
	if carnePreco >= frangoPreco:
		if pao > 2 * carne:
			lucro = carne * carnePreco
			pao -= carne * 2
		else:
			lucro = pao // 2 * carnePreco
			pao = 0
		if pao >= 2:
			if pao > 2 * frango:
				lucro += frango * frangoPreco
				pao -= frango * 2
			else:
				lucro += pao // 2 * frangoPreco
				pao = 0
	elif frangoPreco >= carnePreco:
		if pao > 2 * frango:
			lucro += frango * frangoPreco
			pao -= frango * 2
		else:
			lucro += pao // 2 * frangoPreco
			pao = 0
		if pao >= 2:
			if pao > 2 * carne:
				lucro += carne * carnePreco
				pao -= carne * 2
			else:
				lucro += pao // 2 * carnePreco
				pao = 0
	print(lucro)


q = int(input())
for i in range(q):
	(nb, nh, nc) = map(int, input().split())
	(hp, cp) = map(int, input().split())
	maxp = 0
	x = nb // 2
	if cp > hp:
		if x >= nc:
			maxp += nc * cp
			x -= nc
		else:
			maxp += x * cp
			x -= x
		if x > 0 and x >= nh:
			maxp += nh * hp
		elif x > 0 and x < nh:
			maxp += x * hp
	else:
		if x >= nh:
			maxp += nh * hp
			x -= nh
		else:
			maxp += x * hp
			x -= x
		if x > 0 and x >= nc:
			maxp += nc * cp
		elif x > 0 and x < nc:
			maxp += x * cp
	print(maxp)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
t = nextInt()
for _ in range(t):
	(b, p, f) = [nextInt() for _ in range(3)]
	(h, c) = (nextInt(), nextInt())
	(b, beef, chicken) = (b // 2, (h, p), (c, f))
	(bigger, other) = (max(beef, chicken), min(chicken, beef))
	res = 0
	to_produce = min(bigger[1], b)
	res += to_produce * bigger[0]
	b -= to_produce
	if b > 0:
		to_produce = min(other[1], b)
		res += to_produce * other[0]
	print(res)


t = int(input())
for _ in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b //= 2
	if c > h:
		(c, h) = (h, c)
		(p, f) = (f, p)
	res = 0
	if p >= b:
		print(b * h)
		continue
	else:
		res += p * h
		b -= p
	if f >= b:
		print(b * c + res)
	else:
		print(res + f * c)


for _ in range(int(input())):
	(b, m, c) = map(int, input().split())
	(m_price, c_price) = map(int, input().split())
	n = min(int(b / 2), m + c)
	if m_price > c_price:
		res = min(n, m) * m_price
		res += min(n - m, c) * c_price if n - m > 0 else 0
	else:
		res = min(n, c) * c_price
		res += min(n - c, m) * m_price if n - c > 0 else 0
	print(res)


t = int(input())
for i in range(t):
	(b, p, f) = [int(s) for s in input().split(' ')]
	(h, c) = [int(s) for s in input().split(' ')]
	count = b // 2
	out = 0
	if h > c:
		num = min(count, p)
		out += h * num
		count -= num
		num = min(count, f)
		out += c * num
		count -= num
	else:
		num = min(count, f)
		out += c * num
		count -= num
		num = min(count, p)
		out += h * num
		count -= num
	print(out)


n = int(input())
result = []
for i in range(n):
	(x, y, z) = list(map(int, input().strip().split()))
	(d1, d2) = list(map(int, input().strip().split()))
	b = 0
	c = 0
	if d1 >= d2:
		while y > 0 and x > 1:
			x -= 2
			y -= 1
			b += 1
	if d1 < d2:
		while z > 0 and x > 1:
			x -= 2
			z -= 1
			c += 1
	while y > 0 and x > 1:
		x -= 2
		y -= 1
		b += 1
	while z > 0 and x > 1:
		x -= 2
		z -= 1
		c += 1
	result.append(b * d1 + c * d2)
for num in result:
	print(num)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : [int(i) for i in inp().split()]
li0 = lambda x: [0 for i in range(x)]
stent = lambda : [i for i in inp()]
t = iinp()
for _ in range(t):
	(b, p, f) = ent()
	(h, c) = ent()
	if b < 2:
		print(0)
		continue
	par = b // 2
	if par >= p + f:
		print(p * h + f * c)
		continue
	if h >= c:
		ham = p * h if p <= par else par * h
		par -= p
		po = (f * c if f <= par else par * c) if par > 0 else 0
		print(ham + po)
		continue
	if c > h:
		po = f * c if f <= par else par * c
		par -= f
		ham = (p * h if p <= par else par * h) if par > 0 else 0
		print(ham + po)
		continue


t = int(input())
for i in range(t):
	(b, p, f) = tuple((int(x) for x in input().split()))
	(h, c) = tuple((int(x) for x in input().split()))
	total_profit = 0
	max_ingredient = p if h > c else f
	max_price = max(h, c)
	min_ingredient = p if h <= c else f
	min_price = min(h, c)
	total_profit += min(max_ingredient, b // 2) * max_price
	b -= min(max_ingredient, b // 2) * 2
	total_profit += min(min_ingredient, b // 2) * min_price
	print(total_profit)


q = int(input())
r = 0
for i in range(q):
	w = list(map(int, input().split()))
	e = list(map(int, input().split()))
	if e[0] > e[1]:
		if w[0] // 2 > w[1]:
			r += e[0] * w[1]
			w[0] -= 2 * w[1]
		else:
			r += e[0] * (w[0] // 2)
			w[0] = 0
		r += e[1] * min(w[0] // 2, w[2])
		print(r)
		r = 0
	else:
		if w[0] // 2 > w[2]:
			r += e[1] * w[2]
			w[0] -= 2 * w[2]
		else:
			r += e[1] * (w[0] // 2)
			w[0] = 0
		r += e[0] * min(w[0] // 2, w[1])
		print(r)
		r = 0


n = int(input())
for i in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if h > c:
		a1 = min(p, b // 2)
		ans += a1 * h
		b -= a1 * 2
		a2 = min(f, b // 2)
		ans += a2 * c
	else:
		a2 = min(f, b // 2)
		ans += a2 * c
		b -= a2 * 2
		a1 = min(p, b // 2)
		ans += a1 * h
	print(ans)


t = int(input(''))
i = 0
while i < t:
	i = i + 1
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	(bun, patty, cutlet) = (lst1[0], lst1[1], lst1[2])
	(ham, chicken) = (lst2[0], lst2[1])
	sum = 0
	remain_poss = int(bun / 2)
	if ham > chicken:
		if remain_poss >= patty:
			sum = sum + ham * patty
			remain_poss = remain_poss - patty
			if remain_poss >= cutlet:
				sum = sum + chicken * cutlet
			else:
				sum = sum + chicken * remain_poss
		else:
			sum = sum + ham * remain_poss
	elif remain_poss >= cutlet:
		sum = sum + chicken * cutlet
		remain_poss = remain_poss - cutlet
		if remain_poss >= patty:
			sum = sum + ham * patty
		else:
			sum = sum + ham * remain_poss
	else:
		sum = sum + chicken * remain_poss
	print(sum)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	maxb = b // 2
	if h >= c:
		bur = min(maxb, p)
		cbur = min(maxb - bur, f)
	else:
		cbur = min(maxb, f)
		bur = min(maxb - cbur, p)
	print(bur * h + cbur * c)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	(b, p, f) = mapin()
	(h, c) = mapin()
	b //= 2
	ans = 0
	if h > c:
		ans += h * min(b, p)
		b -= min(b, p)
		ans += c * min(b, f)
		b -= min(b, f)
	else:
		ans += c * min(b, f)
		b -= min(b, f)
		ans += h * min(b, p)
		b -= min(b, p)
	print(ans)


import copy
num = int(input())
for i in range(0, num):
	(b, p, f) = [int(v) for v in input().split()]
	(h, c) = [int(v) for v in input().split()]
	max_buns = b // 2
	max1_h = min(b // 2, p)
	max1_c = min(b // 2 - max1_h, f)
	max2_c = min(b // 2, f)
	max2_h = min(b // 2 - max2_c, p)
	print(max(max1_h * h + max1_c * c, max2_c * c + max2_h * h))


def profit(b, f, c):
	pro = 0
	if b >= 2 * f:
		pro = c * f
		b = b - 2 * f
	else:
		pro = b // 2 * c
		b = 0
	j = [b, pro]
	return j
for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h < c:
		pro = profit(b, f, c)
		if pro[0] == 0:
			print(pro[1])
			continue
		else:
			pro1 = profit(pro[0], p, h)
			print(pro[1] + pro1[1])
	else:
		pro = profit(b, p, h)
		if pro[0] == 0:
			print(pro[1])
			continue
		else:
			pro1 = profit(pro[0], f, c)
			print(pro[1] + pro1[1])
			continue


for _ in range(int(input())):
	(buns, beef, chicken) = map(int, input().split())
	(hb, cb) = map(int, input().split())
	mxburgers = buns // 2
	profit = 0
	if hb >= cb:
		profit = min(mxburgers, beef) * hb + min((mxburgers - min(mxburgers, beef), chicken)) * cb
		print(profit)
	else:
		profit = min(mxburgers, chicken) * cb + min((mxburgers - min(mxburgers, chicken), beef)) * hb
		print(profit)


from math import log
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(int, stdin.readline().split())
lst = lambda : list(map(float, stdin.readline().split()))
slst = lambda : list(sip())
M = pow(10, 9) + 7
for _ in range(inp()):
	(b, p, f) = mulip()
	(h, c) = mulip()
	ans = 0
	if h > c:
		if b // 2 > p:
			ans = p * h + min((b - p * 2) // 2, f) * c
		else:
			ans = b // 2 * h
	elif b // 2 > f:
		ans = f * c + min((b - f * 2) // 2, p) * h
	else:
		ans = b // 2 * c
	print(ans)


n = int(input())
mas1 = [None] * n
mas2 = [None] * n
for i in range(n):
	mas1[i] = list(map(int, input().split()))
	mas2[i] = list(map(int, input().split()))
for i in range(n):
	bul = mas1[i][0] // 2
	gov = mas1[i][1]
	kur = mas1[i][2]
	cost_gov = mas2[i][0]
	cost_kur = mas2[i][1]
	if cost_gov > cost_kur:
		if gov > bul:
			print(cost_gov * bul)
		else:
			print(cost_gov * gov + min(bul - gov, kur) * cost_kur)
	elif kur > bul:
		print(cost_kur * bul)
	else:
		print(cost_kur * kur + min(bul - kur, gov) * cost_gov)


for i in range(int(input())):
	X = list(map(int, input().split()))
	Prices = list(map(int, input().split()))
	SUM = 0
	if Prices[0] > Prices[1]:
		SUM += min(X[0] // 2, X[1]) * Prices[0]
		print(SUM + min(X[0] // 2 - min(X[0] // 2, X[1]), X[2]) * Prices[1])
	else:
		SUM += min(X[0] // 2, X[2]) * Prices[1]
		print(SUM + min(X[0] // 2 - min(X[0] // 2, X[2]), X[1]) * Prices[0])


from sys import stdin
t = int(stdin.readline().rstrip())
while t > 0:
	(b, p, f) = map(int, stdin.readline().split())
	(h, c) = map(int, stdin.readline().split())
	if b < 2:
		print(0)
	else:
		s = 0
		pairs = b // 2
		if c > h:
			m = min(f, pairs)
			s += m * c
			f -= m
			pairs -= m
			m = min(p, pairs)
			s += m * h
		else:
			m = min(p, pairs)
			s += m * h
			p -= m
			pairs -= m
			m = min(f, pairs)
			s += m * c
		print(s)
	t -= 1


q = int(input())
ans_list = []
for i in range(q):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	no_of_burger_possible = b // 2
	if b == 0 or b == 1:
		ans = 0
		ans_list.append(ans)
	elif c > h:
		if no_of_burger_possible > p + f:
			ans = c * f + h * p
			ans_list.append(ans)
		elif no_of_burger_possible < p + f:
			if f >= no_of_burger_possible:
				ans = no_of_burger_possible * c
				ans_list.append(ans)
			else:
				ans = f * c + (no_of_burger_possible - f) * h
				ans_list.append(ans)
		else:
			ans = h * p + c * f
			ans_list.append(ans)
	elif c < h:
		if no_of_burger_possible > p + f:
			ans = h * p + c * f
			ans_list.append(ans)
		elif no_of_burger_possible < p + f:
			if p >= no_of_burger_possible:
				ans = no_of_burger_possible * h
				ans_list.append(ans)
			else:
				ans = p * h + (no_of_burger_possible - p) * c
				ans_list.append(ans)
		else:
			ans = h * p + c * f
			ans_list.append(ans)
	elif p >= no_of_burger_possible:
		ans = no_of_burger_possible * c
		ans_list.append(ans)
	else:
		ans = p * c + f * c
		ans_list.append(ans)
for e in ans_list:
	print(e)


import math
for i in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	ans = 0
	if b == 1:
		print(0)
	elif h > c:
		if p >= b // 2:
			ans += h * (b // 2)
			b -= b
			print(ans)
		else:
			ans += h * p
			b -= p * 2
			ans += min(b // 2, f) * c
			print(ans)
	elif f >= b // 2:
		ans += c * (b // 2)
		b -= b
		print(ans)
	else:
		ans += c * f
		b -= f * 2
		ans += min(b // 2, p) * h
		print(ans)


query = int(input())
for q in range(query):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if b // 2 >= p + f:
		print(p * h + f * c)
	elif h >= c:
		if b // 2 >= p:
			print(p * h + c * (b // 2 - p))
		else:
			print(b // 2 * h)
	elif b // 2 >= f:
		print(f * c + h * (b // 2 - f))
	else:
		print(b // 2 * c)


import math
number = int(input())
for iteration in range(0, number):
	size = []
	price = []
	for t in input().split(' '):
		size.append(int(t))
	for t in input().split(' '):
		price.append(int(t))
	maxBurg = math.floor(size[0] / 2)
	money = 0
	if price[1] > price[0]:
		if maxBurg > size[2]:
			maxBurg = maxBurg - size[2]
			money = money + size[2] * price[1]
		else:
			money = money + maxBurg * price[1]
			maxBurg = 0
		if maxBurg > size[1]:
			maxBurg = maxBurg - size[1]
			money = money + size[1] * price[0]
		else:
			money = money + maxBurg * price[0]
			maxBurg = 0
	if price[0] >= price[1]:
		if maxBurg > size[1]:
			maxBurg = maxBurg - size[1]
			money = money + size[1] * price[0]
		else:
			money = money + maxBurg * price[0]
			maxBurg = 0
		if maxBurg > size[2]:
			maxBurg = maxBurg - size[2]
			money = money + size[2] * price[1]
		else:
			money = money + maxBurg * price[1]
			maxBurg = 0
	print(money)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
for i in range(iread()):
	(b, p, f) = viread()
	(h, c) = viread()
	b = b // 2
	if h > c:
		count1 = min(b, p)
		count2 = min(b - count1, f)
		print(str(int(count1 * h + count2 * c)))
	else:
		count1 = min(b, f)
		count2 = min(b - count1, p)
		print(str(int(count1 * c + count2 * h)))


t = int(input())
for i in range(t):
	(b, p, f) = list(map(int, input().split()))
	(h, c) = list(map(int, input().split()))
	amt = 0
	if c >= h:
		while f > 0:
			flag = 0
			if b - 2 >= 0:
				b = b - 2
				flag = 1
				amt += c
			if flag == 1:
				f -= 1
			else:
				break
		while p > 0:
			flag = 0
			if b - 2 >= 0:
				b = b - 2
				flag = 1
				amt += h
			if flag == 1:
				p -= 1
			else:
				break
	else:
		while p > 0:
			flag = 0
			if b - 2 >= 0:
				b = b - 2
				flag = 1
				amt += h
			if flag == 1:
				p -= 1
			else:
				break
		while f > 0:
			flag = 0
			if b - 2 >= 0:
				b = b - 2
				flag = 1
				amt += c
			if flag == 1:
				f -= 1
			else:
				break
	print(amt)


t = int(input())
for x in range(t):
	(a, b, c) = map(int, input().split())
	(d, e) = map(int, input().split())
	f = a // 2
	if d >= e:
		h = f - b
		if h >= 0:
			sum = h
			s = min(sum, c)
			print(b * d + s * e)
		else:
			sum = f
			print(f * d)
	else:
		h = f - c
		if h >= 0:
			sum = h
			s = min(sum, b)
			print(c * e + s * d)
		else:
			sum = f
			print(f * e)


for _ in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	burger = b // 2
	if burger != 0:
		if burger >= p + f:
			print(f * c + p * h)
		elif c > h:
			a = burger - f
			if a == 0:
				print(burger * c)
			elif a < 0:
				print(burger * c)
			else:
				print(a * h + f * c)
		else:
			a = burger - p
			if a == 0:
				print(burger * h)
			elif a < 0:
				print(burger * h)
			else:
				print(a * c + p * h)
	else:
		print(0)


t = int(input())
for _ in range(t):
	ans = 0
	(b, p, c) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	for i in range(p + 1):
		rem = b - 2 * i
		if rem < 0:
			continue
		tmp = i * c1
		for j in range(c + 1):
			rem2 = rem - j * 2
			if rem2 < 0:
				continue
			ans = max(ans, tmp + j * c2)
	print(ans)


n = int(input())
for i in range(n):
	materials = list(map(int, input().split()))
	precios = list(map(int, input().split()))
	pan = materials[0] // 2
	hamburger = chiken = 0
	if precios[0] >= precios[1]:
		while pan > 0 and materials[1] > 0:
			pan -= 1
			materials[1] -= 1
			hamburger += 1
		while pan > 0 and materials[2] > 0:
			materials[2] -= 1
			pan -= 1
			chiken += 1
	else:
		while pan > 0 and materials[2] > 0:
			pan -= 1
			materials[2] -= 1
			chiken += 1
		while pan > 0 and materials[1] > 0:
			pan -= 1
			materials[1] -= 1
			hamburger += 1
	print(hamburger * precios[0] + chiken * precios[1])


for _ in range(int(input())):
	profit = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	n = min(b // 2, p + f)
	if h > c:
		ham = min(n, p)
		profit = ham * h
		n -= ham
		if n > 0:
			chicken = min(n, f)
			profit += chicken * c
	elif h < c:
		chicken = min(n, f)
		profit = chicken * c
		n -= chicken
		if n > 0:
			ham = min(n, p)
			profit += ham * h
	else:
		profit = n * h
	print(profit)


n = int(input())
for _ in range(n):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	res = 0
	if h > c:
		count = min(b // 2, p)
		res += h * count
		b -= 2 * count
		count = min(b // 2, f)
		res += c * count
	else:
		count = min(b // 2, f)
		res += c * count
		b -= 2 * count
		count = min(b // 2, p)
		res += h * count
	print(res)


def solve(b, ingMai, ingMen, mai, men):
	if ingMai > b // 2:
		return b // 2 * mai
	lucro = ingMai * mai
	b -= 2 * ingMai
	if ingMen > b // 2:
		return lucro + b // 2 * men
	else:
		return lucro + ingMen * men
t = int(input())
for i in range(t):
	(b, p, f) = [int(x) for x in input().split(' ')]
	(h, c) = [int(x) for x in input().split(' ')]
	lucro = 0
	if h > c:
		lucro = solve(b, p, f, h, c)
	else:
		lucro = solve(b, f, p, c, h)
	print(lucro)


t = int(input())
for _ in range(0, t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	b = b // 2
	ss = 0
	if b:
		if h < c:
			ss += min(b, f) * c
			l = b - min(b, f)
			if l > 0:
				ss += min(l, p) * h
				print(ss)
			else:
				print(ss)
		elif h > c:
			ss += min(b, p) * h
			l = b - min(b, p)
			if l > 0:
				ss += min(l, f) * c
				print(ss)
			else:
				print(ss)
		else:
			ss += min(b, f) * c
			l = b - min(b, f)
			if l > 0:
				ss += min(l, p) * h
				print(ss)
			else:
				print(ss)
	else:
		print(ss)


for i in range(int(input())):
	(b, p, f) = (int(j) for j in input().split())
	(h, c) = (int(j) for j in input().split())
	s = 0
	if h >= c:
		if b >= 2 * p:
			b -= 2 * p
			s += p * h
			if b >= 2 * f:
				s += f * c
			else:
				s += b // 2 * c
		else:
			s += b // 2 * h
	elif b >= 2 * f:
		b -= 2 * f
		s += f * c
		if b >= 2 * p:
			s += p * h
		else:
			s += b // 2 * h
	else:
		s += b // 2 * c
	print(s)


class Burger:

	def __init__(self, qntd, valor):
		self.qntd = qntd
		self.valor = valor

def main():
	t = int(input())
	for _ in range(t):
		(p, b, f) = [int(x) for x in input().split()]
		(h, c) = [int(x) for x in input().split()]
		s = p // 2
		B = [Burger(f, c), Burger(b, h)]
		print(solve(B, s))

def solve(B, s):
	B.sort(key=lambda B: B.valor, reverse=True)
	resto = s - B[0].qntd
	if B[0].qntd >= s:
		return s * B[0].valor
	elif B[1].qntd >= resto:
		return B[0].qntd * B[0].valor + resto * B[1].valor
	else:
		return B[0].qntd * B[0].valor + B[1].qntd * B[1].valor
main()


t = int(input())
for d in range(0, t):
	(b, p, f) = [int(a) for a in input().split(' ')]
	(h, c) = [int(a) for a in input().split(' ')]
	if h < c:
		(p, f, h, c) = (f, p, c, h)
	b = b // 2
	if b < p:
		p = b
	b = b - p
	if b < f:
		f = b
	print(p * h + f * c)


def burger(b, p, f, pc, fc):
	no_burg = b // 2
	if p + f <= no_burg:
		return p * pc + f * fc
	if pc < fc:
		(p, f) = (f, p)
		(pc, fc) = (fc, pc)
	if p >= no_burg:
		return no_burg * pc
	ans = p * pc
	no_burg -= p
	if f >= no_burg:
		ans += no_burg * fc
	else:
		ans += f * fc
	return ans
t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(pc, fc) = map(int, input().split())
	print(burger(b, p, f, pc, fc))


test = int(input())
while test:
	count = 0
	test = test - 1
	arr = input().split()
	arr = list(map(int, arr))
	brr = list(map(int, input().split()))
	if brr[1] > brr[0]:
		while arr[0] > 1 and arr[2] > 0:
			count = count + brr[1]
			arr[0] = arr[0] - 2
			arr[2] = arr[2] - 1
		while arr[0] > 1 and arr[1] > 0:
			count = count + brr[0]
			arr[0] = arr[0] - 2
			arr[1] = arr[1] - 1
	else:
		while arr[1] > 0 and arr[0] > 1:
			count = count + brr[0]
			arr[0] = arr[0] - 2
			arr[1] = arr[1] - 1
		while arr[0] > 1 and arr[2] > 0:
			count = count + brr[1]
			arr[0] = arr[0] - 2
			arr[2] = arr[2] - 1
	print(count)


[a] = map(int, input().split())
for i in range(a):
	l = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	b = l[0] // 2
	mx = 0
	for q in range(l[1] + 1):
		for w in range(l[2] + 1):
			if b - q - w >= 0:
				if mx < q * l2[0] + w * l2[1]:
					mx = q * l2[0] + w * l2[1]
	print(mx)


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pr = 0
	if h > c:
		while 2 * p > b:
			p = p - 1
		pr = pr + p * h
		b = b - 2 * p
		while 2 * f > b:
			f = f - 1
		pr = pr + f * c
		print(pr)
	else:
		while 2 * f > b:
			f = f - 1
		pr = pr + f * c
		b = b - 2 * f
		while 2 * p > b:
			p = p - 1
		pr = pr + p * h
		print(pr)


x = int(input())
arr = []
for i in range(2 * x):
	arr.append(list(map(int, input().split())))
for l in range(0, 2 * x - 1, 2):
	profit = 0
	buns = arr[l][0]
	hp = arr[l][1]
	cp = arr[l][2]
	chp = arr[l + 1][0]
	ccp = arr[l + 1][1]
	if buns // 2 > hp + cp:
		profit = ccp * cp + chp * hp
	elif chp > ccp:
		if buns // 2 > hp:
			remain = buns // 2 - hp
			profit = remain * ccp + hp * chp
		else:
			profit = buns // 2 * chp
	elif ccp > chp:
		if buns // 2 > cp:
			remain = buns // 2 - cp
			profit = remain * chp + cp * ccp
		else:
			profit = buns // 2 * ccp
	elif ccp == chp:
		profit = buns // 2 * ccp
	print(profit)


queries = int(input())
prices = []
mats = []
for i in range(queries):
	mats.append(input())
	prices.append(input())
for i in range(queries):
	prof = 0
	(b, p, f) = mats[i].split()
	(b, p, f) = (int(b), int(p), int(f))
	(h, c) = prices[i].split()
	(h, c) = (int(h), int(c))
	while b >= 2:
		if h >= c and p > 0:
			prof += h
			p -= 1
		elif h >= c and f > 0:
			prof += c
			f -= 1
		elif c > h and f > 0:
			prof += c
			f -= 1
		elif c > h and p > 0:
			prof += h
			p -= 1
		b -= 2
	print(prof)


test = int(input())
k = 0
while k < test:
	(buns, beef, chicken) = input().split()
	buns = int(buns)
	beef = int(beef)
	chicken = int(chicken)
	(beefPrice, chickenPrice) = input().split()
	beefPrice = int(beefPrice)
	chickenPrice = int(chickenPrice)
	bunsAvailable = int(buns / 2)
	if bunsAvailable == 0:
		print(0)
	elif beefPrice > chickenPrice:
		if bunsAvailable <= beef:
			print(bunsAvailable * beefPrice)
		else:
			sum = 0
			beefBurger = beef
			bunsAvailable -= beef
			chickenBurger = min(bunsAvailable, chicken)
			sum = beefBurger * beefPrice + chickenBurger * chickenPrice
			print(sum)
	elif bunsAvailable <= chicken:
		print(bunsAvailable * chickenPrice)
	else:
		sum = 0
		chickenBurger = chicken
		bunsAvailable -= chicken
		beefBurger = min(bunsAvailable, beef)
		sum = beefBurger * beefPrice + chickenBurger * chickenPrice
		print(sum)
	k += 1


T = int(input())
ans = list()
for i in range(T):
	supply = input().split()
	cost = input().split()
	buns = int(supply[0]) // 2
	if buns == 0:
		ans.append(0)
		continue
	beef = int(supply[1])
	chicken = int(supply[2])
	beefbun = int(cost[0])
	chickenbun = int(cost[1])
	income = 0
	if chickenbun > beefbun:
		if buns < chicken:
			income += chickenbun * buns
			ans.append(income)
			continue
		else:
			income += chickenbun * chicken
			buns -= chicken
			income += beefbun * min(buns, beef)
			ans.append(income)
	elif beefbun > chickenbun:
		if buns < beef:
			income += beefbun * buns
			ans.append(income)
			continue
		else:
			income += beefbun * beef
			buns -= beef
			income += chickenbun * min(buns, chicken)
			ans.append(income)
	else:
		income += beefbun * min(buns, chicken + beef)
		ans.append(income)
for i in ans:
	print(i)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	ans = 0
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		if b >= 2 * p:
			ans += p * h
			b -= 2 * p
		else:
			ans += b // 2 * h
			b = b - 2 * (b // 2)
		if b >= 2 * f:
			ans += f * c
			b -= 2 * f
		else:
			ans += b // 2 * c
			b = b - 2 * (b // 2)
	else:
		if b >= 2 * f:
			ans += f * c
			b -= 2 * f
		else:
			ans += b // 2 * c
			b = b - 2 * (b // 2)
		if b >= 2 * p:
			ans += p * h
			b -= 2 * p
		else:
			ans += b // 2 * h
			b = b - 2 * (b // 2)
	print(ans)


for x in range(int(input())):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	if h >= c:
		nh = min(b // 2, p)
		nc = min((b - nh * 2) // 2, f)
		print(nh * h + nc * c)
	else:
		nc = min(b // 2, f)
		nh = min((b - nc * 2) // 2, p)
		print(nh * h + nc * c)


import sys

def burgerprice(materials, prices):
	materials = materials.split(' ')
	materials = [int(i) for i in materials]
	prices = prices.split(' ')
	prices = [int(x) for x in prices]
	rem = materials[0] % 2
	bun_pairs = (materials[0] - rem) / 2
	if prices[0] > prices[1]:
		bad_price = 1
		good_price = 0
		meat = 1
		not_meat = 2
	else:
		meat = 2
		good_price = 1
		not_meat = 1
		bad_price = 0
	if bun_pairs >= materials[meat]:
		profit = materials[meat] * prices[good_price]
		bun_pairs -= materials[meat]
		if bun_pairs >= materials[not_meat]:
			profit += materials[not_meat] * prices[bad_price]
			return int(profit)
		else:
			profit += bun_pairs * prices[bad_price]
			return int(profit)
	else:
		profit = bun_pairs * prices[good_price]
		return int(profit)
queries = int(input())
for i in range(queries):
	materials1 = input()
	prices1 = input()
	print(burgerprice(materials1, prices1))


t = int(input())
for j in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	max_b = b // 2
	if max_b < 1:
		print(0)
		continue
	if p + f <= max_b:
		print(int(p * h + f * c))
	elif h > c:
		if p < max_b:
			print(int(p * h + c * (max_b - p)))
		else:
			print(int(max_b * h))
	elif h == c:
		print(int(max_b * h))
	elif f < max_b:
		print(int(f * c + h * (max_b - f)))
	else:
		print(int(max_b * c))


def profit(b, p, f, h, c):
	ans = 0
	buns_c = f * 2
	buns_p = p * 2
	if h >= c:
		if buns_p >= b:
			return b // 2 * h
		else:
			b -= buns_p
			ans += p * h
		if buns_c >= b:
			val = b // 2 * c
			return ans + val
		else:
			val = f * c
			return ans + val
	else:
		if buns_c >= b:
			return b // 2 * c
		else:
			b -= buns_c
			ans += f * c
		if buns_p >= b:
			val = b // 2 * h
			return ans + val
		else:
			val = p * h
			return ans + val
t = int(input())
for i in range(t):
	x = list(map(int, input().rstrip().split()))
	y = list(map(int, input().rstrip().split()))
	b = x[0]
	p = x[1]
	f = x[2]
	h = y[0]
	c = y[1]
	if b == 0 or b == 1:
		print(0)
	else:
		print(profit(b, p, f, h, c))


def Bitplus():
	n = int(input())
	x = 0
	for i in range(n):
		a = input()
		if '+' in a:
			x += 1
		else:
			x -= 1
	print(x)

def GiftSetidk():
	n = int(input())
	for i in range(n):
		all = input().split(' ')
		x = int(all[0])
		y = int(all[1])
		a = int(all[2])
		b = int(all[3])
		counter = 0
		count = True
		while count:
			if x >= a and y >= b:
				x -= a
				y -= b
				counter += 1
			elif x >= b and y >= a:
				x -= b
				y -= a
				counter += 1
			else:
				count = False
		print(counter)

def Team():
	n = int(input())
	problemcount = 0
	for i in range(n):
		count = 0
		answer = input().split(' ')
		for i in range(len(answer)):
			answer[i] = int(answer[i])
		for i in answer:
			if i == 1:
				count += 1
		if count >= 2:
			problemcount += 1
	print(problemcount)

def NextRound():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	print(n, k)
	scores = input().split(' ')
	count = 0
	for i in range(n):
		scores[i] = int(scores[i])
	five = scores[k]
	for i in range(n):
		if scores[i] >= five and scores[i] > 0:
			count += 1
	print(count)

def Beautifulmatrix():
	steps = 0
	matrixes = []
	for i in range(5):
		i = [input().split(' ')]
		matrixes += i
	for i in range(5):
		for j in range(5):
			matrixes[i][j] = int(matrixes[i][j])
	for i in range(5):
		for j in range(5):
			if matrixes[i][j] > 0:
				x = j
				y = i
				break
	while x != 2 or y != 2:
		if x > 2:
			x -= 1
			steps += 1
		elif x < 2:
			x += 1
			steps += 1
		elif y > 2:
			y -= 1
			steps += 1
		elif y < 2:
			y += 1
			steps += 1
	print(steps)

def HelpfulMahts():
	s = input().split('+')
	s.sort()
	print('+'.join(s))

def WordCapitalization():
	word = input()
	List = []
	for i in word:
		List.append(i)
	List[0] = List[0].upper()
	s = ''
	for i in List:
		s += i
	print(s)

def Stonesonthetable():
	n = int(input())
	stones = []
	rrg = input()
	counter = 0
	for i in rrg:
		stones.append(i)
	for i in range(n - 1):
		if stones[i] == stones[i + 1]:
			counter += 1
	print(counter)

def BearandBigBrother():
	inpuut = input().split(' ')
	a = int(inpuut[0])
	b = int(inpuut[1])
	year = 0
	while a <= b:
		a *= 3
		b *= 2
		year += 1
	print(year)

def Wrongsubtraction():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	for i in range(k):
		p = str(n)
		if p[len(p) - 1] == '0':
			n //= 10
		else:
			n -= 1
	print(n)
import string

def Word():
	word = input()
	lower = 0
	upper = 0
	for i in word:
		if i in string.ascii_lowercase:
			lower += 1
		else:
			upper += 1
	if upper > lower:
		word = word.upper()
	else:
		word = word.lower()
	print(word)

def QueueattheSchool():
	nt = input().split(' ')
	n = nt[0]
	t = int(nt[1])
	a = input()
	b = []
	ref = ''
	for i in a:
		b.append(i)
	for k in range(t):
		whre = []
		for i in range(len(b) - 1):
			if b[i] == 'B' and b[i + 1] != 'B':
				whre.insert(0, i)
		for j in whre:
			b.pop(j)
			b.insert(j + 1, 'B')
	for i in b:
		ref += i
	print(ref)

def Nearlyluckynumber():
	n = input()
	if n.count('7') + n.count('4') == 7 or n.count('7') + n.count('4') == 4:
		print('YES')
	else:
		print('NO')

def Translation():
	s = input()
	t = input()
	n = []
	for i in t:
		n.insert(0, i)
	t = ''
	for i in n:
		t += i
	if t == s:
		print('YES')
	else:
		print('NO')

def ANTONandDanik():
	n = int(input())
	s = input()
	A = s.count('A')
	D = s.count('D')
	if A > D:
		print('Anton')
	elif D > A:
		print('Danik')
	else:
		print('Friendship')

def GeorgeandAccomodation():
	n = int(input())
	rooms = 0
	for i in range(n):
		pq = input().split(' ')
		p = int(pq[0])
		q = int(pq[1])
		if q - p >= 2:
			rooms += 1
	print(rooms)

def Magnets():
	n = int(input())
	Rows = []
	groups = 1
	for i in range(n):
		Rows += [input()]
	for i in range(n - 1):
		if Rows[i] != Rows[i + 1]:
			groups += 1
	print(groups)

def InSearcoanEasyProblem():
	n = int(input())
	counter = 0
	s = input().split(' ')
	if '1' in s:
		print('HARD')
	else:
		print('EASY')

def Hulk():
	c = int(input())
	i = 'I'
	s = ''
	it = 'it'
	for i in range(1, c + 1):
		if i == 1:
			s += 'hate '
		elif i % 2 == 0:
			s += 'that I love '
		else:
			s += 'that I hate '
	print(f'I {s}it')

def CalculatingFunctionidk():
	n = int(input())
	c = 0
	for i in range(1, n + 1):
		if i % 2 != 0:
			c -= i
		else:
			c += i
	print(c)

def IWannaBetheGuyidk():
	n = int(input())
	p = input().split(' ')
	q = input().split(' ')
	counter = 0
	for i in range(1, n + 1):
		if str(i) in p or str(i) in q:
			counter += 1
	if counter == n:
		print('I become the guy.')
	else:
		print('Oh, my keyboard!')

def horsesheo():
	n = input().split(' ')
	many = 4
	whatwas = []
	for i in range(len(n)):
		n[i] = int(n[i])
		if n[i] not in whatwas:
			whatwas.append(n[i])
	print(many - len(whatwas))

def ArrivaloftheGeneralidk():
	n = int(input())
	a = input().split(' ')
	max = 0
	minlist = []
	for i in range(n):
		a[i] = int(a[i])
	for i in a:
		if i > max:
			max = i
	maxloc = a.index(max)
	for i in a:
		minlist.insert(0, i)
	min = max
	for i in a:
		if i < min:
			min = i
	minloc = minlist.index(min)
	print(minloc + maxloc)

def UltraFastMathematician():
	first = input()
	second = input()
	s = ''
	for i in range(len(first)):
		if first[i] == '0' and second[i] == '1':
			s += '1'
		elif first[i] == '1' and second[i] == '0':
			s += '1'
		elif first[i] == '0' and second[i] == '0':
			s += '0'
		elif first[i] == '1' and second[i] == '1':
			s += '0'
	print(s)

def Insomniacure():
	klmn = []
	for i in range(4):
		klmn.append(int(input()))
	d = int(input())
	List = []
	if 1 in klmn:
		return d
	for i in range(4):
		mulit = klmn[i]
		while klmn[i] <= d:
			if klmn[i] not in List:
				List.append(klmn[i])
			klmn[i] += mulit
	return len(List)

def AntonandLetters():
	first = input()
	List = []
	for i in first:
		if i not in List and i in string.ascii_lowercase:
			List.append(i)
	print(len(List))

def Pangram():
	n = int(input())
	word = input().lower()
	List = []
	if n >= 26:
		for i in word:
			if i not in List:
				List.append(i)
		if len(List) == 26:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def Collectingcoons():
	n = int(input())
	for i in range(n):
		abcd = input().split(' ')
		for i in range(len(abcd)):
			abcd[i] = int(abcd[i])
		d = abcd[3]
		abcd.pop()
		maxi = 0
		for i in abcd:
			if i > maxi:
				maxi = i
		allindexes = [0, 1, 2]
		indexmax = abcd.index(maxi)
		allindexes.pop(indexmax)
		allminus = 0
		for i in allindexes:
			allminus += abcd[indexmax] - abcd[i]
		d -= allminus
		if d % 3 == 0 and d >= 0:
			print('YES')
		else:
			print('NO')

def Brainsphotos():
	nm = input().split(' ')
	colors = []
	for i in range(int(nm[0])):
		colors += input().split(' ')
	for i in colors:
		if i == 'C' or i == 'M' or i == 'Y':
			return '#Color'
	return '#Black&White'

def SerejaandDima():
	n = int(input())
	card = input().split(' ')
	S = 0
	D = 0
	sturn = True
	for i in range(n):
		if int(card[0]) > int(card[len(card) - 1]):
			if sturn:
				S += int(card[0])
				card.pop(0)
				sturn = False
			else:
				D += int(card[0])
				card.pop(0)
				sturn = True
		elif sturn:
			S += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = False
		else:
			D += int(card[len(card) - 1])
			card.pop(len(card) - 1)
			sturn = True
	print(f'{S} {D}')

def Vanyaandcubes():
	n = int(input())
	counter = 1
	countdodo = 0
	rows = 0
	while n > 0:
		countdodo += counter
		counter += 1
		rows += 1
		n -= countdodo
	if n == 0:
		print(rows)
	else:
		print(rows - 1)

def GennadyandaCarGame():
	card = input()
	cards = input().replace(' ', '')
	for i in card:
		for j in cards:
			if i == j:
				return 'YES'
	return 'NO'

def FafaandhisCompany():
	n = int(input())
	ways = 0
	for i in range(1, n):
		a = n
		a -= i
		if a % i == 0:
			ways += 1
	print(ways)

def Mahmoudandehabandtheevenoddgame():
	n = int(input())
	Mahmoudsturn = True
	Mahmoudlsot = False
	Ehablost = False
	a = 0
	while not Mahmoudlsot and (not Ehablost):
		if Mahmoudsturn:
			if n % 2 == 0 and n >= 2:
				Ehablost = True
			elif n % 2 != 0 and n >= 2:
				a = n - 1
			else:
				Mahmoudlsot = True
		elif n % 2 == 1 and n >= 1:
			Mahmoudlsot = True
		elif n % 2 == 0 and n >= 1:
			a = n - 1
		else:
			Ehablost = False
		n -= a
		if Mahmoudsturn == True:
			Mahmoudsturn = False
		else:
			Mahmoudsturn = True
	if Mahmoudlsot == True:
		print('Ehab')
	else:
		print('Mahmoud')

def FloorNumber():
	t = int(input())
	for i in range(t):
		nx = input().split(' ')
		n = int(nx[0])
		x = int(nx[1])
		aparteements = 2
		floor = 1
		while n > aparteements:
			aparteements += x
			floor += 1
		print(floor)

def VustheCossackandaContest():
	nmk = input().split(' ')
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	if n <= m and n <= k:
		print('Yes')
	else:
		print('No')

def NightattheMuseum():
	word = input()
	rotations = 0
	lower = string.ascii_lowercase + string.ascii_lowercase + string.ascii_lowercase
	loc = lower.index('a', 26, 2 * 26)
	for i in word:
		cplus = loc
		cminus = loc
		keep = True
		while keep:
			if i == lower[cplus] or i == lower[cminus]:
				keep = False
			else:
				cplus += 1
				cminus -= 1
				rotations += 1
				loc = lower.index(i, 26, 2 * 26)
	print(rotations)

def OrdinarYnumbers():
	n = int(input())
	for i in range(n):
		k = int(input())
		counter = 0
		for j in range(1, k + 1):
			a = str(j)
			if len(a) == a.count(a[0]):
				counter += 1
		print(counter)

def DieRoll():
	n = input().split(' ')
	y = int(n[0])
	w = int(n[1])
	number = 0
	dec = 6
	if y >= w:
		for i in range(y, 7):
			number += 1
	else:
		for i in range(w, 7):
			number += 1
	if number % 6 == 0:
		number = number // 6
		dec = 1
	elif number % 3 == 0:
		number = number // 3
		dec = 2
	elif number % 2 == 0:
		number = number // 2
		dec = 3
	print(f'{number}/{dec}')

def Borze():
	n = input()
	l = ''
	k = ''
	for i in n:
		if i == '.' and len(l) == 0:
			k += '0'
		else:
			l += i
			if len(l) == 2:
				if l == '-.':
					k += '1'
					l = ''
				else:
					k += '2'
					l = ''
	print(k)

def FairPlayoff():
	n = int(input())
	for i in range(n):
		loser = {}
		winner = {}
		count = 0
		k = input().split(' ')
		if int(k[0]) > int(k[1]):
			loser['one'] = int(k[1])
			winner['two'] = int(k[0])
		else:
			loser['one'] = int(k[0])
			winner['two'] = int(k[1])
		if int(k[2]) > int(k[3]):
			loser['two'] = int(k[3])
			winner['one'] = int(k[2])
		else:
			loser['two'] = int(k[2])
			winner['one'] = int(k[3])
		for i in loser:
			if loser[i] < winner[i]:
				count += 1
		if count >= 2:
			print('YES')
		else:
			print('NO')

def Bustoudaylanbd():
	n = int(input())
	s = []
	rem = -1
	first = True
	ss = ''
	for i in range(n):
		s += input().split('|')
	for i in range(len(s)):
		if s[i] == 'OO' and first:
			rem = i
			s[i] = '++'
			first = False
	for i in range(len(s)):
		if i % 2 == 0:
			ss += s[i] + '|'
		else:
			ss += s[i] + '\n'
	if not first:
		print('YES')
		print(ss)
	else:
		print('NO')

def Maximumincrease():
	n = int(input())
	arraa = input().split(' ')
	for i in range(len(arraa)):
		arraa[i] = int(arraa[i])
	counter = {}
	for i in range(n):
		counter[i] = 0
	count = 0
	last = 0
	for i in arraa:
		if i > last:
			last = i
			counter[count] += 1
		else:
			last = i
			count += 1
			counter[count] += 1
	max = 0
	for i in range(n):
		if counter[i] > max:
			max = counter[i]
	print(max)

def Jugglingletters():
	n = int(input())
	for i in range(n):
		k = int(input())
		s = ''
		map = {}
		possible = True
		for i in range(k):
			s += input()
		for i in s:
			if i not in map:
				map[i] = 1
			else:
				map[i] += 1
		for i in map:
			if map[i] % k != 0:
				possible = False
		if possible:
			print('YES')
		else:
			print('NO')

def Panoramixsprediction():
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	first = True
	for i in range(n + 1, m):
		count = 0
		for j in range(2, i):
			if i % j == 0:
				count += 1
		if count == 0:
			first = False
			break
	if first:
		count = 0
		for j in range(2, m):
			if m % j == 0:
				count += 1
		if count == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')

def ThreepilesofCanides():
	k = int(input())
	for i in range(k):
		n = input().split(' ')
		canides = 0
		for i in n:
			canides += int(i)
		if canides % 2 != 0:
			canides -= 1
		print(canides // 2)

def filename():
	n = int(input())
	name = input()
	more = 0
	map = {}
	map[more] = 0
	count = 0
	for i in name:
		if i == 'x':
			map[more] += 1
		elif map[more] != 0:
			more += 1
			map[more] = 0
	for i in map:
		if map[i] >= 3:
			while map[i] > 2:
				map[i] -= 1
				count += 1
	print(count)

def Football():
	map = {}
	current = 0
	s = input()
	f = s[0]
	map[current] = 0
	check = False
	for i in s:
		if i == f:
			map[current] += 1
		else:
			current += 1
			map[current] = 1
			f = i
	for i in map:
		if map[i] >= 7:
			check = True
	if check:
		print('YES')
	else:
		print('NO')

def CombinationLock1():
	n = int(input())
	fl = input()
	sl = input()
	count = 0
	for i in range(n):
		goup = int(fl[i])
		god = int(fl[i])
		cu = 0
		cd = 0
		keep = True
		while keep:
			if goup + 1 <= 9:
				goup += 1
				cu += 1
			else:
				goup = 0
				cu += 1
			if god - 1 >= 0:
				god -= 1
				cd += 1
			else:
				god = 9
				cd += 1
			if goup == int(sl[i]):
				count += cu
				keep = False
			elif god == int(sl[i]):
				count += cd
				keep = False
	print(count)

def Watermelon():
	n = int(input())
	down = n // 2
	up = n - down
	rge = up
	for i in range(rge):
		if up % 2 == 0 and down % 2 == 0:
			return print('YES')
		elif up + 1 < n and down - 1 > 0:
			up += 1
			down -= 1
		else:
			return print('NO')

def Dominopiling():
	nk = input().split(' ')
	n = int(nk[0])
	k = int(nk[1])
	mnk = n * k
	print(mnk // 2)

def yetanotherBookshelf():
	n = int(input())
	for i in range(n):
		le = int(input())
		K = input().split(' ')
		SK = []
		lili = []
		for i in range(le):
			if i + 1 <= le - 1:
				if K[i] == '1' and K[i + 1] == '1':
					lili.append(i)
		lili.reverse()
		for i in lili:
			K.pop(i)
		coun = 0
		while K.count('1') > 1:
			f = K.index('1')
			K.pop(f)
			K.insert(f + 1, '1')
			f += 1
			if K[f + 1] == '1':
				K.pop(f)
			coun += 1
		print(coun)

def Combinationlockittakestolong():
	n = int(input())
	fl = input()
	sl = input()
	counter = 0
	for i in range(n):
		up = int(fl[i])
		down = int(fl[i])
		while True:
			if up + 1 <= 9:
				up += 1
			else:
				up = 0
			if down - 1 >= 0:
				down -= 1
			else:
				down = 9
			counter += 1
			if up == int(sl) or down == int(sl):
				break

def iwannabetheguytolong():
	n = int(input())
	lvl = input().split(' ')
	lvls = input().split(' ')
	for i in range(1, n + 1):
		if str(i) not in lvl and str(i) not in lvls:
			return print('Oh, my keyboard!')
	return print('I become the guy.')

def giftsettolong():
	n = int(input())
	for i in range(n):
		rb = input().split(' ')
		x = int(rb[0])
		y = int(rb[1])
		a = int(rb[2])
		b = int(rb[3])
		giftset = 0
		while True:
			if x - a >= 0 and y - b >= 0:
				x -= a
				y -= b
				giftset += 1
			elif x - b >= 0 and y - a >= 0:
				x -= b
				y -= a
				giftset += 1
			else:
				break
		print(giftset)

def uniquwbidauctiontime():
	n = int(input())
	for i in range(n):
		k = int(input())
		list = input().split(' ')
		o = -1
		for i in range(k):
			if list.count(list[i]) == 1:
				if o == -1 or list[i] < o:
					o = list[i]
		if o != -1:
			print(list.index(o) + 1)
		else:
			print(o)

def equalizepriceagain():
	n = int(input())
	for i in range(n):
		k = int(input())
		numbers = input().split(' ')
		for i in range(len(numbers)):
			numbers[i] = int(numbers[i])
		total = 0
		for i in numbers:
			total += i
		if total % k == 0:
			print(total // k)
		else:
			while total % k != 0:
				total += 1
			print(total // k)

def shortsubstrings():
	n = int(input())
	for i in range(n):
		s = input()
		laist = []
		for i in range(len(s)):
			if i % 2 != 0 and i != len(s) - 1:
				laist.append(i)
		laist.reverse()
		s = list(s)
		for i in laist:
			s.pop(i)
		sa = ''
		for i in s:
			sa += i
		print(sa)

def policerecruits():
	n = int(input())
	k = input().split(' ')
	officers = 0
	crimes = 0
	for i in k:
		if int(i) == -1:
			if officers == 0:
				crimes += 1
			else:
				officers -= 1
		else:
			officers += int(i)
	print(crimes)

def thenewyear():
	xxx = input().split(' ')
	for i in range(len(xxx)):
		xxx[i] = int(xxx[i])
	xxx.sort()
	way = 0
	way += abs(int(xxx[1]) - int(xxx[0]))
	way += abs(int(xxx[1]) - int(xxx[2]))
	print(way)

def frogjumpingtimelimit():
	n = int(input())
	for i in range(n):
		abk = input().split(' ')
		a = int(abk[0])
		b = int(abk[1])
		k = int(abk[2])
		all = 0
		for i in range(k):
			if i % 2 == 0:
				all += a
			else:
				all -= b
		print(all)

def patrickandshopping():
	d = input().split(' ')
	d3 = 0
	for i in range(len(d)):
		if int(d[i]) > d3:
			d3 = int(d[i])
	d.pop(d.index(str(d3)))
	d1 = int(d[0])
	d2 = int(d[1])
	distance = d1 + d2
	if d3 <= distance:
		distance += d3
	else:
		distance += distance
	print(distance)

def Freeicecream():
	nx = input().split(' ')
	n = int(nx[0])
	ice = int(nx[1])
	diskid = 0
	for i in range(n):
		k = input().split(' ')
		if k[0] == '+':
			ice += int(k[1])
		elif ice >= int(k[1]):
			ice -= int(k[1])
		else:
			diskid += 1
	print(ice, diskid)

def Reviewsite():
	t = int(input())
	for i in range(t):
		n = int(input())
		upvotes = 0
		votes = input().split(' ')
		for i in votes:
			if i != '2':
				upvotes += 1
		print(upvotes)

def Lastyeasrtssubstring():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		if s[0:4] == '2020' or s[n - 4:n] == '2020':
			print('YES')
		elif s[0:3] == '202' and s[n - 1] == '0':
			print('YES')
		elif s[n - 3:n] == '020' and s[0] == '2':
			print('YES')
		elif s[0:2] == '20' and s[n - 2] == '20':
			print('YES')
		elif s[n - 2:n] == '20' and s[0:2] == '20':
			print('YES')
		else:
			print('NO')

def Arena():
	t = int(input())
	for i in range(t):
		n = int(input())
		heros = input().split(' ')
		heorsint = [int(i) for i in heros]
		heorsint.sort()
		min = heorsint[0]
		winner = n - heorsint.count(min)
		print(winner)

def twoRabbitstoolongbutright():
	t = int(input())
	for i in range(t):
		xyab = input().split(' ')
		x = int(xyab[0])
		y = int(xyab[1])
		a = int(xyab[2])
		b = int(xyab[3])
		seconds = 0
		while x < y:
			x += a
			y -= b
			seconds += 1
		if x == y:
			print(seconds)
		else:
			print(-1)

def systemofequations():
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	nm = [int(i) for i in nm]
	nm.sort()
	count = 0
	for i in range(nm[0] + 1):
		for j in range(nm[0] + 1):
			if i ** 2 + j == n and j ** 2 + i == m:
				count += 1
	print(count)

def polycarpwspockets():
	n = int(input())
	coins = input().split(' ')
	coins = [int(i) for i in coins]
	pocket = 0
	for i in coins:
		nmumbver = coins.count(i)
		if nmumbver > pocket:
			pocket = nmumbver
	print(pocket)

def repeaqtijgcipher():
	n = int(input())
	s = input()
	counter = 0
	rep = 1
	ns = ''
	while counter < n:
		counter += rep
		ns += s[counter - 1]
		rep += 1
	print(ns)

def Neaarestinterestingnumber():
	a = input()
	s = int(a)
	while True:
		if sum((int(i) for i in str(s))) % 4 == 0:
			return print(s)
		else:
			s += 1

def therearetwotzpesofburgers():
	t = int(input())
	for i in range(t):
		ess = input().split(' ')
		ess = [int(i) for i in ess]
		price = input().split(' ')
		buns = int(ess[0])
		totalmoney = 0
		first = True
		if int(price[0]) > int(price[1]):
			patties = ess[1]
			otherpatties = ess[2]
			money = int(price[0])
			othermoney = int(price[1])
		else:
			patties = ess[2]
			otherpatties = ess[1]
			money = int(price[1])
			othermoney = int(price[0])
		keep = True
		while keep:
			if buns - 2 >= 0 and patties - 1 >= 0:
				buns -= 2
				patties -= 1
				totalmoney += money
			elif buns - 2 >= 0 and patties == 0:
				if first:
					patties = otherpatties
					money = othermoney
					first = False
				else:
					print(totalmoney)
					keep = False
			else:
				print(totalmoney)
				keep = False
therearetwotzpesofburgers()


n = int(input())
for i in range(n):
	global b
	(b, f, p) = map(int, input().split())
	(x, y) = map(int, input().split())
	sum = 0

	def profit_p(b, p, y):
		global sum
		while b > 1 and p > 0:
			sum = sum + y
			p = p - 1
			b = b - 2
		return (sum, b)

	def profit_f(b, f, x):
		global sum
		while b > 1 and f > 0:
			sum = sum + x
			f = f - 1
			b = b - 2
		return (sum, b)
	if b <= 1:
		print(sum)
	elif y > x:
		(a1, b) = profit_p(b, p, y)
		(a2, b) = profit_f(b, f, x)
		print(a2)
	else:
		(a1, b) = profit_f(b, f, x)
		(a2, b) = profit_p(b, p, y)
		print(a2)


n = int(input())
for i in range(n):
	(x, y, z) = map(int, input().split())
	(a, b) = map(int, input().split())
	x = x // 2
	if a > b:
		ma = a
		ma_x = y
		mi_z = z
		mi = b
	else:
		ma = b
		ma_x = z
		mi_z = y
		mi = a
	if ma_x > x:
		print(x * ma)
	else:
		total = 0
		total += ma * ma_x
		x = x - ma_x
		if mi_z > x:
			total += x * mi
		else:
			total += mi_z * mi
		print(total)


for y in range(int(input())):
	(n, m, k) = map(int, input().split())
	(a, b) = map(int, input().split())
	maxx = 0
	for i in range(m + 1):
		temp = n - i * 2
		if temp >= 0:
			res1 = i * a
			res2 = min((n - 2 * i) // 2, k) * b
			maxx = max(maxx, res1 + res2)
		else:
			break
	print(maxx)


n = int(input())
for i in range(n):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1[0] = l1[0] // 2
	max_l2 = max(l2)
	count = 0
	if max_l2 == l2[1]:
		count += min(l1[0], l1[2]) * l2[1]
		l1[0] = l1[0] - min(l1[0], l1[2])
		count += min(l1[0], l1[1]) * l2[0]
	elif max_l2 == l2[0]:
		count += min(l1[0], l1[1]) * l2[0]
		l1[0] = l1[0] - min(l1[0], l1[1])
		count += min(l1[0], l1[2]) * l2[1]
	print(count)


def main():
	for _ in range(int(input())):
		(b, p, f) = map(int, input().split())
		(h, c) = map(int, input().split())
		bergers = b // 2
		ans = 0
		if h >= c:
			count = min(p, bergers)
			bergers -= count
			ans += count * h
			count = min(f, bergers)
			f -= count
			bergers -= count
			ans += count * c
		if h < c:
			count = min(f, bergers)
			bergers -= count
			ans += count * c
			count = min(p, bergers)
			ans += count * h
		print(ans)
main()


t = int(input())
for i in range(t):
	(b, p, f) = map(int, input().split())
	(h, c) = map(int, input().split())
	pro = 0
	if h > c:
		while b != 0 and p != 0 and (b > 1):
			pro += h
			b = b - 2
			p -= 1
		if b >= 2:
			while b != 0 and f != 0 and (b > 1):
				pro += c
				b = b - 2
				f -= 1
	elif c > h:
		while b != 0 and f != 0 and (b > 1):
			pro += c
			b = b - 2
			f -= 1
		if b >= 2:
			while b != 0 and p != 0 and (b > 1):
				pro += h
				b = b - 2
				p -= 1
	elif p > f:
		while b != 0 and p != 0 and (b > 1):
			pro += h
			b = b - 2
			p -= 1
		if b >= 2:
			while b != 0 and f != 0 and (b > 1):
				pro += c
				b = b - 2
				f -= 1
	else:
		while b != 0 and f != 0 and (b > 1):
			pro += c
			b = b - 2
			f -= 1
		if b >= 2:
			while b != 0 and p != 0 and (b > 1):
				pro += h
				b = b - 2
				p -= 1
	print(pro)


for i in range(int(input())):
	p = list(map(int, input().split()))
	(hp, cp) = list(map(int, input().split()))
	p[0] = p[0] // 2
	t = 0
	if hp >= cp:
		if p[1] <= p[0]:
			t += p[1] * hp
			p[0] -= p[1]
			if p[0] > 0:
				if p[0] >= p[2]:
					t += p[2] * cp
				elif p[0] < p[2]:
					t += p[0] * cp
		elif p[1] > p[0]:
			t += p[0] * hp
		print(t)
	elif cp > hp:
		if p[2] <= p[0]:
			t += p[2] * cp
			p[0] -= p[2]
			if p[0] > 0:
				if p[0] >= p[1]:
					t += p[1] * hp
				elif p[0] < p[1]:
					t += p[0] * hp
		elif p[2] > p[0]:
			t += p[0] * cp
		print(t)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	t = int1()
	while t > 0:
		(b, p, f) = get_array()
		(h, c) = get_array()
		s = 0
		if h > c:
			r1 = min(b // 2, p)
			s = s + r1 * h
			b = b - 2 * r1
			r = min(b // 2, f)
			s = s + r * c
		else:
			r3 = min(b // 2, f)
			s = s + r3 * c
			b = b - 2 * r3
			r4 = min(b // 2, p)
			s = s + r4 * h
		print(s)
		t = t - 1
main()