import sys input = sys.stdin.readline from itertools import product def kado(A,B,C): if A>0 and B>0 and C>0 and A!=B and A!=C and B!=C and (max(A,B,C)==B or min(A,B,C)==B): return 1 return 0 T=int(input()) for test in range(T): A,B,C,X,Y,Z=map(int,input().split()) S=sorted([A,B,C]) CAN=[S[2]-S[1],S[2]-S[0],S[1]-S[0],0] CAN2=[] for i in CAN: for j in range(i,i+3): if j>=0: CAN2.append(j) P=list(product(CAN2,repeat=3)) ANS=1<<63 for x,y,z in P: if kado(A-x,B-y,C-z)==1: ANS=min(ANS,x*X+y*Y+z*Z) if ANS==1<<63: print(-1) else: print(ANS)