let n = Scanf.scanf "%d\n" (fun x -> x)

let ar =
  Array.init (n - 1) (fun _ ->
      Scanf.scanf "%d %d %d\n" (fun c s f -> (c, s, f)) )


let () =
  Array.iteri
    (fun i (c, s, f) ->
      let tmp = ref (c + s) in
      for i' = i + 1 to n - 2 do
        let nc, ns, nf = ar.(i') in
        if ns < !tmp then
          let ns' =
            if !tmp mod nf = 0 then !tmp else !tmp + ns + !tmp mod nf
          in
          tmp := ns' + nc
        else tmp := ns + nc
      done ;
      Printf.printf "%d\n" !tmp)
    ar ;
  Printf.printf "%d\n" 0