t = int(input()) abc = [[int(i) for i in input().split()] for j in range(t)] for i in range(t): ans = 10**19 a,b,c = abc[i][:3] x,y,z = abc[i][3:] #aがmax if a > 2: tmp = 0 A,B,C = a,b,c if a <= c: tmp += abs(a-1-c)*z C = a-1 if C <= b: if C - 1 <= 0: tmp += 10**19 tmp += abs(C-1-b)*y ans = min(ans,tmp) #bがmax if b > 2: tmp = 0 A,B,C = a,b,c if B <= A: tmp += abs(B-1-A)*x A = B-1 if A <= C: if A - 1 <= 0: tmp += 10**19 tmp += abs(A-1-c)*z ans = min(tmp,ans) #print(tmp,"tmp",i) tmp = 0 A,B,C = a,b,c if B <= C: tmp += abs(B-1-C)*z C = B-1 if C <= A: if C - 1 <= 0: tmp += 10**19 tmp += abs(C-1-A)*x ans = min(tmp,ans) if c > 2: #cがmax tmp = 0 A,B,C = a,b,c if c <= a: tmp += abs(c-1-a)*x A = c-1 if A <= b: if A - 1 <= 0: tmp += 10**19 tmp += abs(A-1-b)*y #print(A,b,"aaab",tmp) ans = min(tmp,ans) if ans != 10**19: print(ans) else: print(-1)