solver::Int->[(Int,Int,Int)]->Int
solver now [] =now
solver now ((c,s,f):sche) = let (r,q)=divMod now f in
                            solver ((max ((r + (if q == 0 then 0 else 1))*f) s)+c) sche

total_solver::[(Int,Int,Int)]->[Int]
total_solver [] = [0]
total_solver sche = (solver 0 sche):(total_solver (tail sche))

n_triple_getter::Int->IO [(Int,Int,Int)]
n_triple_getter 0 = return []
n_triple_getter n = do
  d<-getLine
  let c:s:f:[]=map read (words d)
  rest<-n_triple_getter (n-1)
  return ((c,s,f):rest)

ls_printer::[Int]->IO()
ls_printer [] = return ()
ls_printer (x:xs) = do
  print x
  ls_printer xs

main::IO()
main=do
  nc<-getLine
  let n=read nc
  dat<-n_triple_getter (n-1)
  ls_printer (total_solver dat)