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 rev = 0 if a < c: rev = 1 A = c C = a #print(A,B,C,"abc") if B <= A: if rev == 1: tmp += abs(B-1-A)*z else: tmp += abs(B-1-A)*x A = B-1 if A <= C: if A - 1 <= 0: tmp += 10**19 if rev == 1: tmp += abs(A-1-c)*x else: tmp += abs(A-1-c)*z ans = min(tmp,ans) #print(tmp,"tmp",i) 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)