module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Data.Char

solve1 :: Int -> [(Int, Int, Int)] -> Int
solve1 t [] = t
solve1 t ((c, s, f):xs)
    | t < s          = solve1 (s + c) xs
    | t `mod` f == 0 = solve1 (t + c) xs
    | otherwise      = solve1 (k + c) xs
  where
    k = t + f - (t `mod` f)

main :: IO ()
main = do
    n <- readLn
    csf <- replicateM (n - 1) $ do
        [c, s, f] <- fmap read . words <$> getLine :: IO [Int]
        return (c, s, f)
    let qs = init $ tails csf
    forM_ qs $ \xs -> do
        print $ solve1 0 xs
    print 0