Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.

Chefland is holding a virtual marathon for the categories 10 km, 21 km and 42 km having prizes A, B, C (A < B < C) respectively to promote physical fitness. In order to claim the prize in a particular category the person must cover the total distance for that category within D days. Also a single person cannot apply in multiple categories. 

Given the maximum distance d km that Chef can cover in a single day, find the maximum prize that Chef can win at the end of D days. If Chef can't win any prize, print 0.

------ Input Format ------ 

- The first line contains an integer T, the number of test cases. Then the test cases follow. 
- Each test case contains a single line of input, five integers D, d, A, B, C. 

------ Output Format ------ 

For each test case, output in a single line the answer to the problem.

------ Constraints ------ 

$1 ≤ T ≤ 50$
$1 ≤ D ≤ 10$
$1 ≤ d ≤ 5$
$1 ≤ A < B < C ≤ 10^{5}$

----- Sample Input 1 ------ 
3

1 1 1 2 3

10 1 1 2 3

10 3 1 2 3
----- Sample Output 1 ------ 
0

1

2
----- explanation 1 ------ 
Test Case $1$: The maximum distance covered by Chef is $1 \cdot 1 = 1$ km which is less than any of the available distance categories. Hence Chef won't be able to claim a prize in any of the categories.

Test Case $2$: The maximum distance covered by Chef is $10 \cdot 1 = 10$ km which is equal to distance of the first category. Hence Chef can claim the maximum prize of $1$ units.

Test Case $3$: The maximum distance covered by Chef is $10 \cdot 3 = 30$ km which is more than the distance of the second category but less than that of the third category. Hence Chef can claim the maximum prize of $2$ units.

Difficulty: EASY

Solutions:
t = int(input())
while t > 0:
	(d, x, a, b, c) = map(int, input().split())
	o = d * x
	e = 0
	if o >= 42:
		print(c)
	elif o >= 21:
		print(b)
	elif o >= 10:
		print(a)
	else:
		print(e)
	t -= 1


T = int(input())
for i in range(T):
	(D, d, A, B, C) = map(int, input().split())
	if D * d >= 10 and D * d < 21:
		print(A)
	elif D * d >= 21 and D * d < 42:
		print(B)
	elif D * d >= 42:
		print(C)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c, d, e) = map(int, input().split())
	x = a * b
	m = c + d + e
	y = max(c, d, e)
	z = min(c, d, e)
	if x >= 42:
		print(y)
	elif x >= 21:
		print(m - y - z)
	elif x >= 10:
		print(z)
	else:
		print('0')


t = int(input())
for i in range(t):
	(D, d, a, b, c) = map(int, input().split())
	if D * d >= 10 and D * d < 21:
		print(a)
	elif D * d >= 21 and D * d < 42:
		print(b)
	elif D * d >= 42:
		print(c)
	else:
		print(0)


for _ in range(int(input())):
	(D, d, A, B, C) = map(int, input().split())
	res = d * D
	prize = 0 if res < 10 else C if res >= 42 else B if res >= 21 else A
	print(prize)


for _ in range(int(input())):
	(X, Y, A, B, C) = map(int, input().split())
	Z = X * Y
	if Z < 10:
		print('0')
	elif Z >= 10 and Z < 21:
		print(A)
	elif Z >= 21 and Z < 42:
		print(B)
	else:
		print(C)


for i in range(int(input())):
	(m, n, o, p, q) = map(int, input().split())
	maxx = m * n
	if maxx >= 10 and maxx < 21:
		print(o)
	elif maxx >= 21 and maxx < 42:
		print(p)
	elif maxx >= 42:
		print(q)
	else:
		print(0)


for i in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	if a * b >= 41:
		print(e)
	elif a * b >= 21:
		print(d)
	elif a * b >= 10:
		print(c)
	else:
		print(0)


for i in range(int(input())):
	(x, d, a, b, c) = map(int, input().split())
	s = d * x
	if s < 10:
		print('0')
	elif s >= 10 and s < 21:
		print(a)
	elif s >= 21 and s < 42:
		print(b)
	else:
		print(c)


n = int(input())
for i in range(n):
	(a, b, c, d, e) = map(int, input().split())
	if a * b >= 10 and a * b < 21:
		print(c)
	elif a * b >= 21 and a * b < 42:
		print(d)
	elif a * b >= 42:
		print(e)
	else:
		print(0)


for t in range(int(input())):
	(D, d, A, B, C) = map(int, input().split())
	if D * d < 10:
		print('0')
	elif D * d >= 42:
		print(C)
	elif D * d >= 21:
		print(B)
	else:
		print(A)


for _ in range(int(input())):
	(d, d1, a, b, c) = map(int, input().split())
	if d * d1 >= 10 and d * d1 < 21:
		print(a)
	elif d * d1 >= 21 and d * d1 < 42:
		print(b)
	elif d * d1 >= 42:
		print(c)
	else:
		print('0')


T = int(input())
for _ in range(T):
	(D, d, A, B, C) = map(int, input().split())
	max_dis = D * d
	if max_dis >= 42:
		print(C)
	elif max_dis >= 21:
		print(B)
	elif max_dis >= 10:
		print(A)
	else:
		print(0)


for tc in range(int(input())):
	(D, d, a, b, c) = map(int, input().split())
	m = D * d
	if m < 10:
		print('0')
	elif m >= 10 and m < 21:
		print(a)
	elif m >= 21 and m < 42:
		print(b)
	else:
		print(c)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	km = l[0] * l[1]
	if km < 10:
		print('0')
	elif km >= 10 and km < 21:
		print(l[2])
	elif km >= 21 and km < 42:
		print(l[3])
	else:
		print(l[4])


t = int(input())
for i in range(t):
	(D, d, x, y, z) = map(int, input().split())
	a = d * D
	if a < 10:
		print(0)
	elif a >= 10 and a < 21:
		print(x)
	elif a >= 21 and a < 42:
		print(y)
	else:
		print(z)


for i in range(int(input())):
	(total_days, dis_per_day, A, B, C) = map(int, input().split())
	Distance = total_days * dis_per_day
	if Distance >= 42:
		print(C)
	elif Distance >= 21:
		print(B)
	elif Distance >= 10:
		print(A)
	else:
		print(0)


for _ in range(int(input())):
	(s, d, a, b, c) = map(int, input().split())
	t = s * d
	if t > 9 and t < 21:
		print(a)
	elif t > 20 and t < 42:
		print(b)
	elif t > 41 and t <= 50:
		print(c)
	elif t < 10:
		print(0)


t = int(input())
for i in range(t):
	(da, dk, a, b, c) = list(map(int, input().split()))
	if da * dk < 10:
		print(0)
	elif da * dk == 10 or da * dk < 21:
		print(a)
	elif da * dk == 21 or da * dk < 42:
		print(b)
	else:
		print(c)


T = int(input())
for i in range(T):
	data = input().split()
	max_travelled = int(data[0]) * int(data[1])
	if max_travelled >= 42:
		print(int(data[4]))
	elif max_travelled >= 21:
		print(int(data[3]))
	elif max_travelled >= 10:
		print(int(data[2]))
	else:
		zero = 0
		print(zero)


for i in range(int(input())):
	(days, dis_day, a, b, c) = map(int, input().split())
	dis = days * dis_day
	if dis >= 42:
		print(c)
	elif dis >= 21:
		print(b)
	elif dis >= 10:
		print(a)
	else:
		print(0)


for _ in range(int(input())):
	a = list(map(int, input().split()))
	value = a[0] * a[1]
	if value < 10:
		print(0)
	elif value >= 10 and value < 21:
		print(a[2])
	elif value >= 21 and value < 42:
		print(a[3])
	else:
		print(a[4])


t = int(input())
while t > 0:
	(D, d, A, B, C) = map(int, input().split())
	if 10 <= D * d < 21:
		print(A)
	elif 21 <= D * d < 42:
		print(B)
	elif D * d >= 42:
		print(C)
	else:
		print('0')
	t = t - 1


Test = int(input())
for TestCases in range(Test):
	(Days, Distance, CategoryOne, CategoryTwo, CategoryThree) = map(int, input().split())
	DistanceCovered = Days * Distance
	if DistanceCovered >= 42:
		print(CategoryThree)
	elif DistanceCovered >= 21 and DistanceCovered < 42:
		print(CategoryTwo)
	elif DistanceCovered >= 10 and DistanceCovered < 21:
		print(CategoryOne)
	else:
		print(0)


for i in range(int(input())):
	(D, d, A, B, C) = map(int, input().split(' '))
	distance = d * D
	if distance >= 10:
		if distance >= 21:
			if distance >= 42:
				print(C)
			else:
				print(B)
		else:
			print(A)
	else:
		print(0)


for _ in range(int(input())):
	(x, y, a, b, c) = map(int, input().split())
	if x * y >= 42:
		print(c)
	elif x * y >= 21:
		print(b)
	elif x * y >= 10:
		print(a)
	else:
		print(0)


for tc in range(int(input())):
	(D, d, a, b, c) = list(map(int, input().split()))
	res = d * D
	prize = 0 if res < 10 else c if res >= 42 else b if res >= 21 else a
	print(prize)


for _ in range(int(input())):
	(d, km, a, b, c) = map(int, input().split())
	t = d * km
	if t < 10:
		print(0)
	elif 10 <= t < 21:
		print(a)
	elif 21 <= t < 42:
		print(b)
	else:
		print(c)


for i in range(int(input())):
	(days, km_one, a, b, c) = map(int, input().split())
	print(c if days * km_one >= 42 else b if days * km_one >= 21 else a if days * km_one >= 10 else 0)


try:
	t = int(input())
	for r in range(t):
		(d, f, a, b, c) = map(int, input().split())
		g = d * f
		if g >= 10 and g < 21:
			print(a)
		elif g >= 21 and g < 42:
			print(b)
		elif g > 42:
			print(c)
		else:
			print('0')
except:
	pass


t = int(input())
for _ in range(t):
	(D, d, a, b, c) = list(map(int, input().split()))
	res = 0
	total = D * d
	if total >= 10 and total < 21:
		print(a)
	elif total >= 21 and total < 42:
		print(b)
	elif total >= 42:
		print(c)
	else:
		print(0)


for test_case in range(int(input())):
	(D, d, a, b, c) = map(int, input().split())
	prize = 0
	if 10 <= d * D < 21:
		prize = a
	elif 21 <= d * D < 42:
		prize = b
	elif d * D >= 42:
		prize = c
	print(a if prize == a else b if prize == b else c if prize == c else '0')