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**20 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 a, b, c = A, B, C if a == 1 or c == 1 or a == c == 2: ans2 = 10**20 else: ans2 = 0 if a == c: if x < z: ans2 += x a -= 1 else: ans2 += z c -= 1 ans2 += y * max(b - (min(a, b, c) - 1), 0) ans = min(ans1, ans2) if ans == 10**20: print(-1) else: print(ans) if __name__ == '__main__': main()