import qualified Data.ByteString.Char8 as BC
import Data.Maybe

readIntsLines :: IO [[Int]]
readIntsLines = map (map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

simulate :: [[Int]] -> Int -> Int
simulate [] time = time
simulate ([c, s, f]:csfs) time
  | time >= s = let res = time + waittime + c in simulate csfs res
  | otherwise = let res = s + c in simulate csfs res
    where waittime = if time `mod` f == 0 then 0 else time - time `mod` f

solve :: [[Int]] -> [Int]
solve [] = []
solve input@(csf:csfs) = res : solve csfs
  where res = simulate input 0

main :: IO ()
main = do
  getLine
  csfs <- readIntsLines
  mapM_ print $ solve csfs ++ [0]