import sys input = sys.stdin.readline 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 # Wを使う回数で全探索 for i in range(min(A0,B0,C0)+1): ANS=i*W A=A0-i B=B0-i C=C0-i # Xを使う回数で三分探索 MIN=0 MAX=min(A,B) while MAX>MIN+3: mid1=MIN+(MAX-MIN)//3 mid2=MIN+(MAX-MIN)//3*2 ANS1=ANS+mid1*X A1=A-mid1 B1=B-mid1 C1=C ANS11=ANS1+min(B1,C1)*Y ANS11+=min(A1,C1-min(B1,C1))*Z ANS12=ANS1+min(A1,C1)*Z ANS12+=min(B1,C1-min(A1,C1))*Y ANS2=ANS+mid2*X A1=A-mid2 B1=B-mid2 C1=C ANS21=ANS2+min(B1,C1)*Y ANS21+=min(A1,C1-min(B1,C1))*Z ANS22=ANS2+min(A1,C1)*Z ANS22+=min(B1,C1-min(A1,C1))*Y if max(ANS11,ANS12)>max(ANS21,ANS22): MAX=mid2 else: MIN=mid1 #print(i,MIN,MAX) for j in range(MIN,MAX+1): ANS1=ANS+j*X A1=A-j B1=B-j C1=C ANS11=ANS1+min(B1,C1)*Y ANS11+=min(A1,C1-min(B1,C1))*Z ANS12=ANS1+min(A1,C1)*Z ANS12+=min(B1,C1-min(A1,C1))*Y LANS=max(LANS,ANS11,ANS12) print(LANS)