import sys

def solve():
    input = sys.stdin.read().split()
    idx = 0
    T = int(input[idx])
    idx += 1
    for _ in range(T):
        A = int(input[idx])
        B = int(input[idx+1])
        C = int(input[idx+2])
        X = int(input[idx+3])
        Y = int(input[idx+4])
        Z = int(input[idx+5])
        idx +=6
        
        min_cost = float('inf')
        
        # Case 1: B' is the maximum
        # Check if current B is already larger than A and C, and A != C
        if A < B and C < B and A != C:
            min_cost = min(min_cost, 0)
        
        # Try to reduce B by 1 (a + b = 1)
        B_prime = B - 1
        if B_prime > 0:
            # Now, B' = B - 1, which could be the new maximum
            # Check if A' < B' and C' < B' and A' != C'
            for a in [0, 1]:
                b = 1 - a
                # A' = A - a - c
                # C' = C - b - c
                # B' = B - 1
                # Need A' < B' and C' < B'
                # => A - a - c < B - 1
                # => C - b - c < B - 1
                # => c > A - a - (B - 1)
                # => c > C - b - (B - 1)
                min_c = max(A - a - (B_prime) + 1, C - b - (B_prime) + 1, 0)
                max_c_A = A - a - 1  # A' > 0
                max_c_C = C - b - 1  # C' > 0
                max_c = min(max_c_A, max_c_C)
                if min_c > max_c:
                    continue
                # Check if A' != C'
                # A - a - c != C - b - c => A - a != C - b
                if (A - a) == (C - b):
                    continue
                # Find the minimal c
                c = min_c
                cost = X * a + Y * b + Z * c
                if cost < min_cost:
                    min_cost = cost
        
        # Case 2: B' is the minimum
        # Check if current B is smaller than A and C, and A != C
        if B < A and B < C and A != C:
            min_cost = min(min_cost, 0)
        
        # Try to reduce B by 1 (B' = B - 1)
        if B > 1:
            B_prime = B - 1
            # Need A' > B' and C' > B' and A' != C'
            for a in [0, 1]:
                b = 1 - a
                # A' = A - a - c > B_prime
                # C' = C - b - c > B_prime
                # => a + c < A - B_prime
                # => b + c < C - B_prime
                max_c_A = (A - B_prime) - a - 1
                max_c_C = (C - B_prime) - b - 1
                if max_c_A < 0 or max_c_C < 0:
                    continue
                max_c = min(max_c_A, max_c_C)
                if max_c < 0:
                    continue
                # Check if A - a - c != C - b - c
                # A - a != C - b
                if (A - a) == (C - b):
                    continue
                # Minimal c is 0
                c = 0
                # Check if A' and C' are valid
                if (A - a - c) <= B_prime or (C - b - c) <= B_prime:
                    continue
                cost = X * a + Y * b + Z * c
                if cost < min_cost:
                    min_cost = cost
        
        # Check other possibilities where B' is reduced by 2 or more (could be needed in some cases)
        # But for efficiency, we skip further checks and rely on the above
        
        if min_cost == float('inf'):
            print(-1)
        else:
            print(min_cost)

solve()