import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 md = 10**9+7 # md = 998244353 def solve(): a, b, c = LI() x, y, z, w = LI() ans = 0 if x+y+z >= w*2: pre = 0 for _ in range(2): for i in range(min(a, b)+1): j = min(b-i, c) k = min(a-i, c-j) cur = x*i+y*j+z*k+pre if cur > ans: ans = cur k = min(a-i, c) j = min(b-i, c-k) cur = x*i+y*j+z*k+pre if cur > ans: ans = cur if a and b and c: a, b, c = a-1, b-1, c-1 pre = w else: for l in range(min(a, b, c)+1): i = min(a-l, b-l) j = min(b-l-i, c-l) cur = x*i+y*j if cur > ans: ans = cur j = min(b-l, c-l) k = min(c-l-j, a-l) cur = y*j+z*k if cur > ans: ans = cur i = min(a-l, b-l) k = min(a-l-i, c-l) cur = x*i+z*k if cur > ans: ans = cur print(ans) for _ in range(II()): solve()