
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f

let rec drop n xs =
  match xs with
  | [] -> []
  | (_::xs') -> if n = 0 then xs else drop (n-1) xs'

let solve scheds =
  let rec g t xs = match xs with
  | [] -> t
  | ((c, s, f)::xs') ->
    let dept = max s @@ ((t - s) + f - 1) / f * f + s in
    g (dept + c) xs' in
  g 0 scheds

let () =
  let n = read_int () in
  let scheds = for_iter 0 (n-1) (fun _ ->
    let c = read_int () in let s = read_int () in let f = read_int() in
    (c, s, f)) in
  for_iter 0 n (fun i -> solve @@ drop i scheds)
  |> List.iter @@ printf "%d\n"
