import itertools T=int(input()) inf=1<<60 for t in range(T): A,B,C,X,Y,Z=map(int,input().split()) ans=inf for tpl in itertools.permutations(range(3)): if tpl[1]==1: continue ABC=[A,B,C] for i,j in zip(tpl,tpl[1:]): ABC[j]=min(ABC[j],ABC[i]-1) if min(ABC)>0: ans=min(ans,sum((a-aa)*x for a,aa,x in zip((A,B,C),ABC,(X,Y,Z)))) if ans==inf: ans=-1 print(ans)