import sys input = sys.stdin.readline from itertools import permutations def calc1(A,B,C,ANS): M=min(A,B) A-=M B-=M ANS+=M*X return A,B,C,ANS def calc2(A,B,C,ANS): M=min(B,C) B-=M C-=M ANS+=M*Y return A,B,C,ANS def calc3(A,B,C,ANS): M=min(C,A) C-=M A-=M ANS+=M*Z return A,B,C,ANS def calc4(A,B,C,ANS): M=min(A,B,C) A-=M B-=M C-=M ANS+=M*W return A,B,C,ANS T=int(input()) for tests in range(T): A0,B0,C0=map(int,input().split()) X,Y,Z,W=map(int,input().split()) LANS=0 L=list(permutations(range(4))) for lx in L: A=A0 B=B0 C=C0 ANS=0 for com in lx: if com==0: A,B,C,ANS=calc1(A,B,C,ANS) if com==1: A,B,C,ANS=calc2(A,B,C,ANS) if com==2: A,B,C,ANS=calc3(A,B,C,ANS) if com==3: A,B,C,ANS=calc4(A,B,C,ANS) LANS=max(ANS,LANS) if A0>0 and B0>0 and C0>0: A=A0-1 B=B0-1 C=C0-1 ANS=W for com in lx: if com==0: A,B,C,ANS=calc1(A,B,C,ANS) if com==1: A,B,C,ANS=calc2(A,B,C,ANS) if com==2: A,B,C,ANS=calc3(A,B,C,ANS) if com==3: A,B,C,ANS=calc4(A,B,C,ANS) LANS=max(ANS,LANS) print(LANS)