import locale
locale.setlocale(locale.LC_ALL,'')
while 1:
    A=[*map(float,input().split())]
    if A[0]==-1:break
    s=int(A[3])
    del A[3]
    k=3
    print('Month ' + str(s) + ' cost: $', end="")
    while 1:
        if s-1<=2:
            print(locale.format('%.2f',A[s-1],1));break
        else:
            A.append(round(A[k-3]*A[k-2]/A[k-1],2))
            if s-1==k:
                print(locale.format('%.2f',A[k],1));break
            else:k+=1