import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 T=I() inf=10**20 for _ in range(T): ans=inf a,b,c,x,y,z=MI() L=[a,b,c] # bが最大かつa,cが等しくない t=b-1 temp=0 if a>t: temp+=(a-t)*x a=t if c>t: temp+=(c-t)*z c=t if a==c: if x<=z: a-=1 temp+=x else: c-=1 temp+=z if min(a,c)>=1: ans=min(ans,temp) # print(a,b,c,temp) a,b,c=L # bが最小かつa,cが等しくない t=min(L) temp=(b-t)*y b=t if a==b==c: b-=2 if x<=z: a-=1 temp+=2*y+x else: c-=1 temp+=2*y+z elif a==b: b-=1 temp+=y elif b==c: b-=1 temp+=y elif a==c: if x<=z: a-=1 temp+=x if a==b: b-=1 temp+=y else: c-=1 temp+=z if c==b: b-=1 temp+=y if b>=1: ans=min(ans,temp) # print(a,b,c,temp) if ans==inf: print(-1) else: print(ans) main()