T = int(input())
for tc in range(1, T+1):
a_price, b_fixed_price, b_limit, b_price, amount = map(int, input().split())
a = 0
b = 0
a = a_price * amount
if amount <= b_limit:
b = b_fixed_price
else:
b = b_fixed_price + b_price * (amount - b_limit)
if a > b:
print('#{} {}'.format(tc, b))
else:
print('#{} {}'.format(tc, a))