T = int(input())
def solve():
A, B, C, X, Y, D = map(int, input().split())
if D <= X: return A
if D <= X + Y:
if B * X <= A:
return A + B * (D - X)
else:
return min((D + X - 1) // X * A, D // X * A + D % X * B)
else:
if C * X <= A and C * (X + Y) <= A + B * Y:
print('C')
return min(A + B * Y + (D - X - Y) * C, (D + X - 1) // X * A, D // X * A + D % X * B)
elif B * X <= A:
print('B')
AB = A + B * Y
t = D // (X + Y) * AB
D %= X + Y
res = t + (D + X - 1) // X * A - (X - D % X) % X * B
if D > X:
res = min(res, t + A + (D - X) * B)
res = min(res, t + D * C)
return res
else:
print('A')
k = D // X
t = D // X * A
D %= X
res = t + A
if D <= Y:
res = min(res, t + D * B)
else:
res = min(res, t + Y * B + (D - Y) * C)
res = min(res, t + min(D, k * Y) * B + (D - min(D, k * Y)) * C)
return res
assert False
for _ in range(T):
print(solve())