import Control.Monad
import Data.List

main = do
  n <- readLn
  a <- map (map read . words) <$> replicateM (n - 1) getLine
  forM_ [0..n-1] $ \i ->
    print $ solve (drop i a)

solve :: [[Int]] -> Int
solve = foldl' f 0
  where
    f :: Int -> [Int] -> Int
    f curr [c, s, f] = max s ((curr + f - 1) `div` f * f) + c
  
