def main(): import sys input = sys.stdin.readline T = int(input()) for _ in range(T): A, B, C, x, y, z = map(int, input().split()) # b max if B <= 2: ans1 = 10**30 else: ans1 = 0 a = A b = B c = C if a >= b: ans1 += x * (a - (b-1)) a = b-1 if c >= b: ans1 += z * (c - (b-1)) c = b-1 if a == c: ans1 += min(x, z) # b min if A == 1 or C == 1 or A == C == 2: ans2 = 10**30 else: ans2 = 0 a = A b = B c = C if a == c: if x < z: ans2 += x a -= 1 else: ans2 += z c -= 1 ans2 += y * max(b - (min(a, c) - 1), 0) ans = min(ans1, ans2) if ans == 10**30: print(-1) else: print(ans) if __name__ == '__main__': main()