Cooking Examinations Authority (C.E.A.) is conducting an Ordinary Cooking Level (O.C.L.) test, which tests the candidate skills on three different aspects - Appearance, Flavor and Texture. Chef is planning to appear in this coveted test.

O.C.L. is a 240 \textbf{minute} test consisting of 20 \textbf{problems} on \textbf{each aspect} (and hence total 60 problems).

Chef figured out that for \textbf{each} problem on Appearance, Flavor and Texture
He requires A, B and C minutes respectively to correctly solve that problem. 
He will be awarded X, Y and Z points respectively when correctly solved that problem. 

Chef wonders what are the maximum points P that he can get in O.C.L.? Can you help the Chef? 

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

- The first line of input contains a single integer T, denoting the number of testcases. The description of the T testcases follows.
- The first line of each testcase contains 3 space separated integers A, B and C.
- The second line of each testcase contains 3 space separated integers X, Y and Z.

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

For each testcase, output a single line containing an integer P, which denotes the maximum points that the Chef can score in O.C.L.

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

$1 ≤ T ≤ 100$
$1 ≤ A, B, C ≤ 10$
$1 ≤ X, Y, Z ≤ 10^{6}$

----- Sample Input 1 ------ 
3
4 4 4
5 5 5
5 5 5
10 8 6
5 6 7
5 6 7

----- Sample Output 1 ------ 
300
408
240

----- explanation 1 ------ 
Test Case $1$: Chef can correctly solve all the problems within the time limit, resulting in total $300$ points. 

Test Case $2$: Chef can correctly solve $20$ problems on Appearance, $20$ problems on Flavor and $8$ problems on Texture, resulting in total $408$ points. We can prove that the Chef cannot get more than $408$ points.

Difficulty: HARD
Tags: Constructive algorithms

Ad-hoc

Starter code:

Solutions:
l = []
for h in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	max = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if a * i + b * j + c * k <= 240:
					if max < i * x + j * y + k * z:
						max = i * x + j * y + k * z
	print(max)


n = int(input())
while n != 0:
	(x, y, z) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	ans = 0
	for i in range(0, 21):
		for j in range(0, 21):
			for k in range(0, 21):
				f1 = a * i + b * j + c * k
				time = x * i + y * j + z * k
				if time <= 240:
					ans = max(f1, ans)
	n = n - 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					ans = max(ans, i * x + j * y + k * z)
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	mx = 0
	for i in range(0, 21):
		for j in range(0, 21):
			for k in range(0, 21):
				tot_time = a * i + b * j + c * k
				if tot_time <= 240:
					p = x * i + y * j + z * k
					mx = max(mx, p)
	print(mx)


for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	ans = 0
	for q_a in range(21):
		for q_b in range(21):
			for q_c in range(21):
				if q_a * a + q_b * b + q_c * c <= 240:
					ans = max(ans, q_a * x + q_b * y + q_c * z)
	print(ans)


t = int(input())
for l in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	r = 240
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					r = max(r, i * x + j * y + k * z)
	print(r)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	max_points = time = 0
	for i in range(0, 21):
		for j in range(0, 21):
			for k in range(0, 21):
				time = i * a + j * b + k * c
				if time <= 240:
					max_points = max(max_points, i * x + j * y + k * z)
	print(max_points)


testcase = int(input())
for i in range(testcase):
	(A, B, C) = list(map(int, input().split()))
	(X, Y, Z) = list(map(int, input().split()))
	max_points = time = 0
	for AP in range(0, 21):
		for FL in range(0, 21):
			for TX in range(0, 21):
				time = AP * A + FL * B + TX * C
				if time <= 240:
					max_points = max(max_points, AP * X + FL * Y + TX * Z)
	print(max_points)


def findSum(a, b, c, x, y, z):
	sum = 0
	newSum = 0
	for i in range(1, 21):
		for j in range(0, 21):
			time = a * i + b * j
			if time < 240:
				sum = x * i + y * j
				time = 240 - (a * i + b * j)
				if sum > newSum:
					newSum = sum
				if time != 0:
					fac = time // c
					if fac >= 20:
						sum += z * 20
					else:
						sum += fac * z
				if sum > newSum:
					newSum = sum
	return newSum
t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	avgApp = x / a
	avgFla = y / b
	avgTex = z / c
	time = 240
	sum = 0
	newSum = findSum(a, b, c, x, y, z)
	if newSum > sum:
		sum = newSum
	newSum = findSum(a, c, b, x, z, y)
	if newSum > sum:
		sum = newSum
	newSum = findSum(b, a, c, y, x, z)
	if newSum > sum:
		sum = newSum
	newSum = findSum(b, c, a, y, z, x)
	if newSum > sum:
		sum = newSum
	newSum = findSum(c, b, a, z, y, x)
	if newSum > sum:
		sum = newSum
	newSum = findSum(c, a, b, z, x, y)
	if newSum > sum:
		sum = newSum
	print(sum)


t = int(input())
for tc in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 240
	for ta in range(21):
		for tb in range(21):
			for tc in range(21):
				if ta * a + tb * b + tc * c <= 240:
					ans = max(ans, ta * x + tb * y + tc * z)
	print(ans)


try:
	t = int(input())
	for i in range(t):
		(a, b, c) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		ans = time = 0
		for j in range(21):
			for k in range(21):
				for l in range(21):
					time = j * a + k * b + l * c
					if time <= 240:
						ans = max(ans, j * x + k * y + l * z)
		print(ans)
except:
	pass


for _ in range(int(input())):
	(A, B, C) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	res = 240
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * A + j * B + k * C <= 240:
					res = max(res, i * X + j * Y + k * Z)
	print(res)


for _ in range(int(input())):
	(t1, t2, t3) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	m = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * t1 + j * t2 + k * t3 <= 240:
					if m < i * x + j * y + k * z:
						m = i * x + j * y + k * z
	print(m)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	maxp = 0
	for i in range(0, 21):
		for j in range(0, 21):
			if i * a + j * b > 240:
				break
			else:
				k = min(20, (240 - (i * a + j * b)) // c)
				maxp = max(maxp, i * x + j * y + k * z)
	print(maxp)


try:
	t = int(input())
	for i in range(t):
		(a, b, c) = list(map(int, input().split()))
		(x, y, z) = list(map(int, input().split()))
		li = []
		for i in range(21):
			for j in range(21):
				for k in range(21):
					total_time = a * i + b * j + c * k
					if total_time <= 240:
						score = x * i + y * j + z * k
						li.append(score)
		print(max(li))
except:
	pass


import sys
import io, os
from io import BytesIO, IOBase
input = sys.stdin.readline
from collections import Counter
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
a = inp()

def solve(a, b, c, x, y, z):
	minutes = 240
	max_points = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= minutes:
					max_points = max(max_points, i * x + j * y + z * k)
	return print(max_points)
for _ in range(a):
	(a, b, c) = mul()
	(x, y, z) = mul()
	solve(a, b, c, x, y, z)


for _ in range(int(input())):
	time = list(map(int, input().split()))
	points = list(map(int, input().split()))
	dp = [0 for _ in range(240 + 1)]
	for k in range(3):
		for j in range(20):
			for i in range(240, -1, -1):
				if i - time[k] >= 0:
					dp[i] = max(dp[i], dp[i - time[k]] + points[k])
	print(dp[-1])


for q in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	ans = 0
	for i in range(0, 20 + 1):
		for j in range(0, 20 + 1):
			for k in range(0, 20 + 1):
				temp = i * a + j * b + k * c
				if temp <= 240:
					ans = max(ans, i * x + j * y + k * z)
	print(ans)


for x in range(int(input())):
	ans = 0
	(A, B, C) = list(map(int, input().split()))
	(X, Y, Z) = list(map(int, input().split()))
	for i in range(21):
		for j in range(21):
			for k in range(21):
				time = A * i + B * j + C * k
				if time <= 240:
					ans = max(ans, X * i + Y * j + Z * k)
	print(ans)


T = int(input())
for i in range(T):
	time = list(map(int, input().split()))
	points = list(map(int, input().split()))
	maxpoints = 0
	for ap in range(0, 21):
		for fl in range(21):
			for tx in range(21):
				if ap * time[0] + fl * time[1] + tx * time[2] <= 240:
					temp = ap * points[0] + fl * points[1] + tx * points[2]
					if temp > maxpoints:
						maxpoints = temp
	print(maxpoints)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	rem_time = 240
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					rem_time = max(rem_time, i * x + j * y + k * z)
	print(rem_time)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	(ta, tb, tc) = (20, 20, 20)
	ans = 0
	for i in range(ta + 1):
		for j in range(tb + 1):
			for k in range(tc + 1):
				total_time = i * a + j * b + k * c
				if total_time <= 240:
					ans = max(ans, i * x + j * y + k * z)
	print(ans)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	(k, s) = (0, 0)
	for m in range(21):
		for n in range(21):
			for o in range(21):
				if m * a + n * b + o * c <= 240:
					k = s
					s = x * m + y * n + z * o
					s = max(k, s)
	print(s)


for i in range(int(input())):
	ans = 0
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	for i in range(0, 21):
		for j in range(0, 21):
			for k in range(0, 21):
				tt = l1[0] * i + l1[1] * j + l1[2] * k
				if tt <= 240:
					ans = max(ans, i * l2[0] + j * l2[1] + k * l2[2])
	print(ans)


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

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

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

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

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	(a, b, c) = li()
	(x, y, z) = li()
	store = [[]]
	for i in range(20):
		store.append([a, x])
	for i in range(20):
		store.append([b, y])
	for i in range(20):
		store.append([c, z])
	dp = [[0 for i in range(241)] for j in range(61)]
	maxi = 0
	for i in range(1, 61):
		for j in range(241):
			if store[i][0] + j <= 240:
				dp[i][j + store[i][0]] = max(dp[i - 1][j + store[i][0]], dp[i - 1][j] + store[i][1])
				maxi = max(maxi, dp[i][j + store[i][0]])
	print(maxi)


link = 'https://www.codechef.com/START12C/problems/MAXPOINT'
t = int(input())
while t:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	score = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if a * i + b * j + c * k <= 240:
					score = max(score, i * x + j * y + k * z)
	print(score)
	t -= 1


def solve(t, p):
	best_score = 0
	for x in range(21):
		for y in range(21):
			for z in range(21):
				total_time = x * t[0] + y * t[1] + z * t[2]
				total_score = x * p[0] + y * p[1] + z * p[2]
				if total_time > 240:
					continue
				if total_score > best_score:
					best_score = total_score
	return best_score
for _ in range(int(input())):
	t = list(map(int, input().split()))
	p = list(map(int, input().split()))
	print(solve(t, p))


for x in range(int(input())):
	(A, B, C) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	ans = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				t = i * A + j * B + k * C
				p = i * X + j * Y + k * Z
				if t <= 240 and ans < p:
					ans = p
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	time_left = 240
	max_point = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					max_point = max(max_point, i * x + j * y + k * z)
	print(max_point)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	res = 0
	for __ in range(21):
		for ___ in range(21):
			for ____ in range(21):
				if __ * a + ___ * b + ____ * c < 241:
					res = max(res, __ * x + ___ * y + ____ * z)
	print(res)


def solve(wt, val, W, n):
	if n == 0 or W == 0:
		return 0
	if dic.get(str(W) + '$' + str(n)):
		return dic[str(W) + '$' + str(n)]
	if wt[n - 1] <= W:
		dic[str(W) + '$' + str(n)] = max(val[n - 1] + solve(wt, val, W - wt[n - 1], n - 1), solve(wt, val, W, n - 1))
	else:
		dic[str(W) + '$' + str(n)] = solve(wt, val, W, n - 1)
	return dic[str(W) + '$' + str(n)]
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	wt = [a for i in range(20)]
	val = [x for i in range(20)]
	dic = {}
	for i in range(20):
		wt.append(b)
		val.append(y)
	for i in range(20):
		wt.append(c)
		val.append(z)
	dic = {}
	n = len(val)
	print(solve(wt, val, 240, n))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = -1
	n = 21
	for i in range(n):
		for j in range(n):
			for k in range(n):
				t = a * i + b * j + c * k
				if t <= 240:
					ans = max(ans, x * i + y * j + z * k)
	print(ans)


for q in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	score = 0
	for ta in range(21):
		for tb in range(21):
			for tc in range(21):
				if ta * a + tb * b + tc * c <= 240:
					score = max(score, ta * x + tb * y + tc * z)
	print(score)


import collections
t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	max = 0
	for p in range(0, 21):
		for q in range(0, 21):
			for r in range(0, 21):
				if a * p + b * q + c * r <= 240:
					score = p * x + q * y + r * z
					if score > max:
						max = score
	print(max)


def solve(a, b, c, x, y, z):
	ans = -1
	for p in range(20, -1, -1):
		for q in range(20, -1, -1):
			for r in range(20, -1, -1):
				if p * a + q * b + r * c <= 240:
					ans = max(ans, p * x + q * y + r * z)
	return ans
t = int(input())
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	(x, y, z) = list(map(int, input().split()))
	print(solve(a, b, c, x, y, z))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				total_time = i * a + j * b + k * c
				if total_time <= 240:
					ans = max(ans, i * x + j * y + k * z)
	print(ans)


T = int(input())
while T > 0:
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	ans = 0
	for qa in range(21):
		for qb in range(21):
			for qc in range(21):
				time = qa * a + qb * b + qc * c
				if time <= 240:
					marks = qa * x + qb * y + qc * z
					ans = max(ans, marks)
	print(ans)
	T = T - 1


try:
	for t in range(int(input())):
		(a, b, c) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		time = 0
		pts = 0
		for ta in range(21):
			for tb in range(21):
				for tc in range(21):
					time = a * ta + b * tb + c * tc
					if time <= 240:
						pts = max(pts, x * ta + y * tb + z * tc)
					else:
						break
		print(pts)
except:
	pass


no_of_testcases = int(input())
for i in range(no_of_testcases):
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	result = 0
	for x in range(21):
		for y in range(21):
			for z in range(21):
				first = l[0] * x
				second = l[1] * y
				third = l[2] * z
				if first + second + third <= 240:
					p_score = x * m[0] + y * m[1] + z * m[2]
					result = max(p_score, result)
	print(result)


answer = []
for i in range(int(input())):
	(timeA, timeB, timeC) = [int(j) for j in input().split()]
	(pointA, pointB, pointC) = [int(j) for j in input().split()]
	ans = 0
	for a in range(21):
		for b in range(21):
			for c in range(21):
				totalTime = a * timeA + b * timeB + c * timeC
				if totalTime <= 240:
					ans = max(ans, a * pointA + b * pointB + c * pointC)
	answer.append(ans)
for i in range(len(answer)):
	print(answer[i])


try:
	n = int(input())
	for i in range(n):
		(A, B, C) = map(int, input().split())
		(X, Y, Z) = map(int, input().split())
		max = 0
		for a in range(21):
			for b in range(21):
				for c in range(21):
					time = a * A + b * B + c * C
					marks = X * a + Y * b + Z * c
					if time < 241 and marks > max:
						max = marks
		print(max)
except:
	pass


t = int(input())
while t > 0:
	m = 0
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					m = max(m, i * x + j * y + k * z)
	print(m)
	t = t - 1


t = int(input())
for tt in range(t):
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	result = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * arr[0] + j * arr[1] + k * arr[2] <= 240:
					result = max(result, i * brr[0] + j * brr[1] + k * brr[2])
	print(result)


def maxipoints(a, b, c, x, y, z):
	maxi = 0
	for ta in range(0, 21):
		for tb in range(0, 21):
			for tc in range(0, 21):
				if ta * a + tb * b + tc * c <= 240:
					cm = ta * x + tb * y + tc * z
					maxi = max(cm, maxi)
	return maxi
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	print(maxipoints(a, b, c, x, y, z))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	max_points = 0
	for l in range(21):
		for m in range(21):
			for n in range(21):
				total_time = l * a + m * b + n * c
				if total_time <= 240:
					ans = l * x + m * y + n * z
					max_points = max(max_points, ans)
	print(max_points)


total_time = 240
test_cases = int(input())
for i in range(test_cases):
	mins = list(map(int, input().split()))
	points = list(map(int, input().split()))
	sum_mins = 20 * mins[0] + 20 * mins[1] + 20 * mins[2]
	ans = 0
	for a in range(0, 21):
		for b in range(0, 21):
			for c in range(0, 21):
				time = a * mins[0] + b * mins[1] + c * mins[2]
				if time <= 240:
					ans = max(ans, a * points[0] + b * points[1] + c * points[2])
	print(ans)


for u in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if a[0] * i + a[1] * j + a[2] * k <= 240:
					m = max(b[0] * i + b[1] * j + b[2] * k, m)
	print(m)


t = int(input())
for i in range(0, t):
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	m = 0
	for j in range(0, 21):
		for k in range(0, 21):
			for l in range(0, 21):
				time = a[0] * j + a[1] * k + a[2] * l
				if time <= 240:
					points = x[0] * j + x[1] * k + x[2] * l
					m = max(points, m)
	print(m)


t = int(input())
for k in range(t):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	t = 240
	s = 0
	max = 0
	for i in range(0, 21):
		for j in range(0, 21):
			for q in range(0, 21):
				if l1[0] * i + l1[1] * j + l1[2] * q <= 240:
					s = l2[0] * i + l2[1] * j + l2[2] * q
					if max < s:
						max = s
	print(max)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	l = []
	for m in range(21):
		for n in range(21):
			for o in range(21):
				if m * a + n * b + o * c <= 240:
					l.append(m * x + n * y + o * z)
	print(max(l))


for bg in range(int(input())):
	zx = list(map(int, input().split()))
	zy = list(map(int, input().split()))
	d = 240
	l = []
	p = []
	q = []
	for j in range(21):
		l.append([zx[0] * j, zy[0] * j])
	for j in range(21):
		p.append([zx[1] * j, zy[1] * j])
	for j in range(21):
		q.append([zx[2] * j, zy[2] * j])
	z = []
	b = []
	for i in range(len(l)):
		for h in range(len(p)):
			for r in range(len(q)):
				if l[i][0] + p[h][0] + q[r][0] <= d:
					z.append(l[i][1] + p[h][1] + q[r][1])
					if l[i][0] + p[h][0] + q[r][0] == 240:
						b.append(l[i][1] + p[h][1] + q[r][1])
	if len(b) == 0:
		print(max(z))
	else:
		print(max(max(b), max(z)))


num = int(input())
for i in range(num):
	res = 240
	(A, B, C) = map(int, input().split())
	(X, Y, Z) = map(int, input().split())
	for m in range(21):
		for n in range(21):
			for o in range(21):
				if m * A + B * n + C * o <= 240:
					res = max(res, m * X + n * Y + o * Z)
	print(res)


def solveA():
	for _ in range(int(input())):
		print('YES' if input().count('1') > 3 else 'NO')

def solveB():
	for _ in range(int(input())):
		N = int(input())
		if N == 1:
			print('3')
		elif N == 2:
			print('21')
		else:
			print('11' + '0' * (N - 3) + '1')

def solveC():
	from itertools import permutations
	for _ in range(int(input())):
		T = [int(x) for x in input().split()]
		M = [int(x) for x in input().split()]
		ans = 0
		for i in range(21):
			for j in range(21):
				for k in range(21):
					if i * T[0] + j * T[1] + k * T[2] <= 240:
						temp = i * M[0] + j * M[1] + k * M[2]
						ans = max(ans, temp)
		print(ans)

def solveD():
	for _ in range(int(input())):
		(N, K) = [int(x) for x in input().split()]
		S = [int(x) for x in input()]
		dic = {x: [0, 0] for x in range(K)}
		for (i, s) in enumerate(S):
			dic[i % K][s] += 1
		ans = 0
		for i in range(K):
			ans += min(dic[i])
			if N // K == 1 and sum(dic[i]) == 1 and dic[i][1]:
				ans += 1
		print(ans)
solveC()


def knapsack01(wt, val, w, n, dp):
	if n == 0 or w == 0:
		return 0
	if dp[n][w] != -1:
		return dp[n][w]
	if wt[n - 1] > w:
		ans = knapsack01(wt, val, w, n - 1, dp)
		dp[n][w] = ans
		return ans
	else:
		ans = max(val[n - 1] + knapsack01(wt, val, w - wt[n - 1], n - 1, dp), knapsack01(wt, val, w, n - 1, dp))
		dp[n][w] = ans
		return ans

def knapSack(w, wt, val, n):
	dp = [[-1] * (w + 1) for i in range(0, n + 1)]
	return knapsack01(wt, val, w, n, dp)
t = int(input())
for tc in range(t):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	w = 240
	wt = [a] * 20 + [b] * 20 + [c] * 20
	val = [x] * 20 + [y] * 20 + [z] * 20
	n = 60
	print(knapSack(w, wt, val, n))


for _ in range(int(input())):
	val = list(map(int, input().split()))
	wt = list(map(int, input().split()))
	m = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				t = val[0] * i + val[1] * j + val[2] * k
				if t <= 240:
					p = wt[0] * i + wt[1] * j + wt[2] * k
					m = max(m, p)
	print(m)


def solve(a, b, c, x, y, z):
	res = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					res = max(res, i * x + j * y + k * z)
	print(res)
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	solve(a, b, c, x, y, z)


t = int(input())
while t:
	time = [int(x) for x in input().split()]
	points = [int(x) for x in input().split()]
	maximum = 0
	for i in range(0, 21):
		for j in range(0, 21):
			for k in range(0, 21):
				if time[0] * k + time[1] * j + time[2] * i <= 240:
					maximum = max(maximum, points[0] * k + points[1] * j + points[2] * i)
	print(maximum)
	t -= 1


try:
	t = int(input())
	while t > 0:
		(a, b, c) = map(int, input().split())
		(x, y, z) = map(int, input().split())
		maxpoints = 0
		if 20 * (a + b + c) <= 240:
			maxpoints = 20 * (x + y + z)
		else:
			for i in range(21):
				for j in range(21):
					tl = 240 - (i * a + j * b)
					if tl < 0:
						break
					q = tl // c
					if q > 20:
						q = 20
					points = i * x + j * y + z * q
					if points > maxpoints:
						maxpoints = points
		print(maxpoints)
		t -= 1
except:
	pass


t = int(input())
for t in range(t):
	(a, b, c) = [int(x) for x in input().split()]
	(x, y, z) = [int(x) for x in input().split()]
	currmax = 0
	for i in range(21):
		for j in range(21):
			for k in range(21):
				if i * a + j * b + k * c <= 240:
					if currmax < i * x + j * y + k * z:
						currmax = i * x + j * y + k * z
	print(currmax)


n = input()
n = int(n)
o = ''
for _ in range(n):
	t = input().split()
	t = list(map(int, t))
	m = input().split()
	m = list(map(int, m))
	score_list = []
	for i in range(20 + 1):
		for j in range(20 + 1):
			for k in range(20 + 1):
				time = i * t[0] + j * t[1] + k * t[2]
				if time <= 240:
					score_list.append(i * m[0] + j * m[1] + k * m[2])
	if o == '':
		o = str(max(score_list))
	else:
		o = o + '\n' + str(max(score_list))
print(o)