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

Chefland has $7$ days in a week. Chef is very conscious about his work done during the week.

There are two ways he can spend his energy during the week. The first way is to do $x$ units of work every day and the second way is to do $y$ ($> x$) units of work for the first $d$ ($< 7$) days and to do $z$ ($< x$) units of work thereafter since he will get tired of working more in the initial few days.

Find the maximum amount of work he can do during the week if he is free to choose either of the two strategies.

------  Input ------

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, four integers $d$, $x$, $y$, $z$.

------  Output ------
For each testcase, output in a single line the answer to the problem.

------  Constraints ------
$1 ≤ T ≤ 5\cdot 10^{3}$
$1 ≤ d < 7$
$1 ≤ z < x < y ≤ 18$

------  Subtasks ------
Subtask #1 (100 points): Original constraints

----- Sample Input 1 ------ 
3
1 2 3 1
6 2 3 1
1 2 8 1
----- Sample Output 1 ------ 
14
19
14
----- explanation 1 ------ 
Test Case $1$: Using the first strategy, Chef does $2 \cdot 7 = 14$ units of work and using the second strategy Chef does $3 \cdot 1 + 1 \cdot 6 = 9$ units of work. So the maximum amount of work that Chef can do is $\max(14, 9) = 14$ units by using the first strategy.

Test Case $2$: Using the first strategy, Chef does $2 \cdot 7 = 14$ units of work and using the second strategy Chef does $3 \cdot 6 + 1 \cdot 1 = 19$ units of work. So the maximum amount of work that Chef can do is $\max(14, 19) = 19$ units by using the second strategy.

Difficulty: EASY

Solutions:
def main():
	t = input()
	for i in range(int(t)):
		(d, x, y, z) = map(int, input().split())
		first = x * 7
		second = y * d + (7 - d) * z
		if first >= second:
			print(first)
		elif second > first:
			print(second)
main()


for i in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	print(max(x * 7, y * d + z * (7 - d)))


t = int(input())
for _ in range(t):
	(d, x, y, z) = map(int, input().split())
	left = 7 - d
	s1 = 7 * x
	s2 = d * y + left * z
	print(max(s1, s2))


for t in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	c1 = x * 7
	c2 = y * d + (7 - d) * z
	print(max(c1, c2))


n = int(input())
for i in range(n):
	(d, x, y, z) = map(int, input().split())
	t = x * 7
	k = y * d + (7 - d) * z
	print(max(t, k))


T = int(input())
for i in range(T):
	(d, x, y, z) = map(int, input().split())
	s = x * 7
	t = y * d + z * (7 - d)
	w = max(s, t)
	print(w)


t = int(input())
for i in range(t):
	(d, x, y, z) = map(int, input().split())
	a = x * 7
	b = y * d + z * (7 - d)
	print(max(a, b))


for i in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	if x * 7 > y * d + z * (7 - d):
		print(x * 7)
	else:
		print(y * d + z * (7 - d))


t = int(input())
for i in range(t):
	(d, x, y, z) = map(int, input().split())
	x1 = x * 7
	x2 = y * d + (7 - d) * z
	print(max(x1, x2))


T = int(input())
for i in range(T):
	(d, x, y, z) = map(int, input().split())
	first = 7 * x
	second = d * y + (7 - d) * z
	print(max(first, second))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	print(max(b * 7, c * a + d * (7 - a)))


n = int(input())
for i in range(n):
	(a, b, c, d) = list(map(int, input().split()))
	first_strat = b * 7
	second_strat = c * a + d * (7 - a)
	print(max(first_strat, second_strat))


t = int(input())
for i in range(t):
	(a, b, c, d) = list(map(int, input().split(' ')))
	b = b * 7
	e = 7 - a
	c = int(c * a + d * e)
	print(max(b, c))


T = int(input())
for i in range(T):
	(D, X, Y, Z) = map(int, input().split())
	print(max(X * 7, Y * D + Z * (7 - D)))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	f = b * 7
	g = c * a + d * (7 - a)
	print(max(f, g))


t = int(input())
while t > 0:
	(d, x, y, z) = map(int, input().split())
	print(max(x * 7, y * d + z * (7 - d)))
	t = t - 1


for _ in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	f = x * 7
	s = y * d + z * abs(d - 7)
	print(max(f, s))


testcases = int(input())
for i in range(testcases):
	(D, X, Y, Z) = map(int, input().split())
	if D * Y + (7 - D) * Z > X * 7:
		print(D * Y + (7 - D) * Z)
	else:
		print(X * 7)


t = int(input())
for _ in range(t):
	(d, x, y, z) = list(map(int, input().split()))
	first = x * 7
	second = d * y + z * (7 - d)
	print(max(first, second))


for _ in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	ans = x * 7
	ans1 = d * y + z * (7 - d)
	print(max(ans, ans1))


T = int(input())
for _ in range(T):
	(d, x, y, z) = map(int, input().split())
	option1 = x * 7
	option2 = y * d + z * (7 - d)
	print(max(option1, option2))


t = int(input())
for i in range(0, t):
	(d, x, y, z) = map(int, input().split())
	res1 = x * 7
	res2 = y * d + z * (7 - d)
	if res1 > res2:
		print(res1)
	else:
		print(res2)


n = int(input())
for i in range(1, n + 1):
	(a, b, c, d) = map(int, input().split())
	x = b * 7
	y = c * a + d * (7 - a)
	print(max(x, y))


t = int(input())
while t > 0:
	t = t - 1
	(a, b, c, d) = map(int, input().split())
	j = a * c + (7 - a) * d
	if j >= b * 7:
		print(j)
	else:
		print(b * 7)


t = int(input())
for i in range(t):
	(d, x, y, z) = map(int, input().split())
	work_1 = x * 7
	work_2 = d * y + (7 - d) * z
	if work_1 > work_2:
		print(work_1)
	else:
		print(work_2)


T = int(input())
for i in range(T):
	(d, x, y, z) = map(int, input().split())
	first_strat = x * 7
	second_strat = y * d + z * (7 - d)
	print(max(first_strat, second_strat))


t = int(input())
for i in range(t):
	(d, x, y, z) = map(int, input().split())
	p = x * 7
	q = y * d + z * (7 - d)
	if p >= q:
		print(p)
	else:
		print(q)


n = int(input())
for i in range(n):
	(d, x, y, z) = map(int, input().split())
	fir = 7 * x
	sec = y * d + z * (7 - d)
	print(max(fir, sec))


for _ in range(int(input())):
	(d, x, y, z) = map(int, input().split())
	x = x * 7
	a = y * d + z * (7 - d)
	print(max(x, a))


n = int(input())
for _ in range(n):
	arr = list(map(int, input().split()))
	a = arr[0] * arr[2]
	b = (7 - arr[0]) * arr[3]
	c = a + b
	d = 7 * arr[1]
	if c > d:
		print(c)
	else:
		print(d)


n = int(input())
a = []
b = []
for i in range(0, n):
	x = [int(y) for y in input().split()]
	a.append(x)
for i in range(0, n):
	m = []
	d = a[i][0]
	x = a[i][1]
	y = a[i][2]
	z = a[i][3]
	e1 = 7 * x
	e2 = d * y + (7 - d) * z
	m.append(e1)
	m.append(e2)
	b.append(m)
for i in range(0, len(b)):
	print(max(b[i]))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	n = c * a + d * (7 - a)
	print(max(b * 7, n))


T = int(input())
for i in range(T):
	(d, x, y, z) = map(int, input().split())
	n1 = 7 * x
	n2 = y * d
	n3 = z * (7 - d)
	n4 = n2 + n3
	print(max(n1, n4))


a = int(input())
for i in range(a):
	(d, x, y, z) = map(int, input().split())
	op1 = 7 * x
	op2 = y * d + z * (7 - d)
	if op1 >= op2:
		print(op1)
	else:
		print(op2)


t = int(input())
for i in range(t):
	(d, x, y, z) = [int(j) for j in input().split()]
	if x * 7 >= d * y + (7 - d) * z:
		print(x * 7)
	else:
		print(d * y + (7 - d) * z)


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if b * 7 > c * a + (7 - a) * d:
		print(b * 7)
	else:
		print(c * a + (7 - a) * d)