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: for k in range(min(A0,B0)+1): A=A0-k B=B0-k C=C0 ANS=k*X 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) for k in range(min(B0,C0)+1): A=A0 B=B0-k C=C0-k ANS=k*Y 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) for k in range(min(C0,A0)+1): A=A0-k B=B0 C=C0-k ANS=k*Z 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) for k in range(min(A0,B0,C0)+1): A=A0-k B=B0-k C=C0-k ANS=k*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)