import Control.Monad
import Data.List

main = readLn >>= flip replicateM (map read . words <$> getLine) . (subtract 1) >>= let g t [c,s,f] = c + max s ((t + f - 1) `div` f * f) in mapM_ print . map (foldl g 0) . tails