inf = 10**30 # b > c > a def calc1(a,b,c,x,y,z): count = 0 if b <= c: count += (c-b+1)*z c = b-1 if a >= c: count += (a-c+1)*x a = c-1 if a > 0: return count return inf # c > a > b def calc2(a,b,c,x,y,z): count = 0 if a >= c: count += (a-c+1)*x a = c-1 if b >= a: count += (b-a+1)*y b = a-1 if b > 0: return count return inf t = int(input()) for _ in range(t): a,b,c,x,y,z = map(int,input().split()) ans = min(calc1(a,b,c,x,y,z),calc2(a,b,c,x,y,z),calc1(c,b,a,z,y,x),calc2(c,b,a,z,y,x)) if ans == inf: ans = -1 print(ans)