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()) if A == C == 1: print(-1) continue # b max a, b, c = A, B, C ans1 = 0 if a >= b: d = a - (b-1) ans1 += z * d a -= d c -= d if c >= b: d = c - (b-1) ans1 += z * d a -= d c -= d if a == c: ans11 = ans1 a1, b1, c1 = a, b, c ans11 += x a1 -= 1 b1 -= 1 if b1 == c1: ans11 += z a1 -= 1 c1 -= 1 if a1 <= 0 or b1 <= 0 or c1 <= 0: ans11 = 10**30 ans12 = ans1 a2, b2, c2 = a, b, c ans12 += y c2 -= 1 b2 -= 1 if b2 == a2: ans12 += z a2 -= 1 c2 -= 1 if a2 <= 0 or b2 <= 0 or c2 <= 0: ans12 = 10 ** 30 ans1 = min(ans11, ans12) else: if a <= 0 or b <= 0 or c <= 0: ans1 = 10**30 # b min a, b, c = A, B, C ans2 = 0 if a <= b: d = b - (a-1) ans2 += y * d b -= d c -= d if c <= b: d = b - (c-1) ans2 = x * d a -= d b -= d if a == c: ans2 += min(x, y) b -= 1 if b <= 0: ans2 = 10**30 else: if a <= 0 or b <= 0 or c <= 0: ans2 = 10**30 ans = min(ans1, ans2) if ans != 10**30: print(ans) else: print(-1) if __name__ == '__main__': main()