#================================================== def solve(): A,B,C=map(int,input().split()) X,Y,Z,W=map(int,input().split()) def earning(x,y,z,w): return x*X+y*Y+z*Z+w*W def valid(x,y,z,w): return (x>=0) and (y>=0) and (z>=0) and (w>=0) def calc_A(a,b,c): x=0 y=-a+c z=-b+c w=a+b-c return earning(x,y,z,w) if valid(x,y,z,w) else -1 def calc_B(a,b,c): x=a-c y=0 z=a-b w=-a+b+c return earning(x,y,z,w) if valid(x,y,z,w) else -1 def calc_C(a,b,c): x=b-c y=-a+b z=0 w=a-b+c return earning(x,y,z,w) if valid(x,y,z,w) else -1 def calc_D(a,b,c): if (a+b+c)%2!=0: return -1 x=(a+b-c)//2 y=(-a+b+c)//2 z=(a-b+c)//2 w=0 return earning(x,y,z,w) if valid(x,y,z,w) else -1 def calc_E(a,b,c): if (a+b+c)%2!=1: return -1 x=(a+b-c-1)//2 y=(-a+b+c-1)//2 z=(a-b+c-1)//2 w=1 return earning(x,y,z,w) if valid(x,y,z,w) else -1 def calc(a,b,c): return max( calc_A(a,b,c), calc_B(a,b,c), calc_C(a,b,c), calc_D(a,b,c), calc_E(a,b,c)) ans=0 # (p) イチゴ味を k 食 for k in range(A+1): ans=max(ans, calc(k,B,C)) # (q) メロン味を k 食 for k in range(B+1): ans=max(ans, calc(A,k,C)) # (r) ブルーハワイ味を k 食 for k in range(C+1): ans=max(ans, calc(A,B,k)) return ans #================================================== T=int(input()) print(*[solve() for t in range(T)], sep="\n")