let rec select acc trace = function
  | [] -> acc
  | x :: xs -> select ((trace, x, xs) :: acc) (x :: trace) xs
let select xs = select [] [] xs

let () = Scanf.scanf "%d\n" @@ fun n ->
  let csfs =
    Array.to_list @@
      Array.init (n - 1) @@ fun _ ->
        Scanf.scanf "%d %d %d\n" @@ fun c s f -> c, s, f in
  select csfs
  |> List.rev
  |> List.map (fun (_, _, csfs) -> csfs)
  |> (fun csfss -> csfs :: csfss)
  |> List.map
      (List.fold_left (fun t (c, s, f) ->
        c + max ((t + f - 1) - (t + f - 1) mod f) s) 0)
  |> List.iter (Printf.printf "%d\n")

