import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=mapM_ print.solve.map(unfoldr$B.readInt.B.dropWhile isSpace).B.lines=<<B.getContents
solve=map(foldl' g 0).tails.map(\[c,s,f]->(c,s,f)).tail
g t(c,s,f)=(max t s+f-1)`div`f*f+c