A railroad running from west to east in Atcoder Kingdom is now complete.
There are N stations on the railroad, numbered 1 through N from west to east.
Tomorrow, the opening ceremony of the railroad will take place.
On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.
The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.
Here, it is guaranteed that F_i divides S_i.
That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.
For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

-----Constraints-----
 - 1≤N≤500
 - 1≤C_i≤100
 - 1≤S_i≤10^5
 - 1≤F_i≤10
 - S_i％F_i=0
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

-----Output-----
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

-----Sample Input-----
3
6 5 1
1 10 1

-----Sample Output-----
12
11
0

We will travel from Station 1 as follows:
 - 5 seconds after the beginning: take the train to Station 2.
 - 11 seconds: arrive at Station 2.
 - 11 seconds: take the train to Station 3.
 - 12 seconds: arrive at Station 3.
We will travel from Station 2 as follows:
 - 10 seconds: take the train to Station 3.
 - 11 seconds: arrive at Station 3.
Note that we should print 0 for Station 3.

Difficulty: introductory

Starter code:

Solutions:
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


N = int(input())
X = LIHW(N-1)

for i in range(N-1):
    time = [0]*N
    time[i] = X[i][1]+X[i][0]
    for j in range(i+1, N-1):
        if time[j-1] <= X[j][1]:
            time[j] = X[j][1]+X[j][0]
        else:
            if (time[j-1]-X[j][1]) % X[j][2] == 0:
                time[j] = time[j-1] + X[j][0]
            else:
                time[j] = time[j-1] + X[j][0]+X[j][2] - \
                    ((time[j-1]-X[j][1]) % X[j][2])
    print(time[j])
print(0)

N = int(input())

CSF = []
for _ in range(N-1):
  C, S, F = map(int, input().split())
  CSF.append((C, S, F))

def cnt(x):
  ret = 0
  for i in range(x, N-1):
    C, S, F = CSF[i]
    if ret < S:
      ret = S
      ret += C
    else:
      ret = -(-ret//F)*F
      ret += C
  return ret

for x in range(N):
  print(cnt(x))

N = int(input())
CSF = [list(map(int, input().split())) for i in range(N - 1)]
ans = []
for i in range(N - 1):
    temp = 0
    for j in range(i, N - 1):
        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]
        if temp <= s:
            temp += s - temp
            temp += temp % f
        else:
            temp += (f - ((temp - s) % f)) % f
        temp += c
    ans.append(temp)
for i in range(N - 1):
    print((ans[i]))
print((0))


n = int(input())
l = [list(map(int,input().split())) for i in range(n-1)]
c,s,f = [list(i) for i in zip(*l)]
for _ in range(n-1):
    ans = 0
    for i in range(_,n-1):
        if ans < s[i]:
            ans = s[i]
        elif ans % f[i] == 0:
            pass
        else:
            ans += f[i] - (ans % f[i])
        ans += c[i]
    print(ans)
print(0)

n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
    time = 0
    while True:
        if i == n-1:
            print(time)
            break
        if csf[i][1] <= time and time%csf[i][2] == 0:
            time += csf[i][0]
        elif csf[i][1] > time:
            time = csf[i][1] + csf[i][0]
        else:
            time += csf[i][2] - time%csf[i][2] + csf[i][0]
        i += 1

N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N

for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

def arrive(st):
    time = C[st] + S[st]
    for i in range(st + 1, N-1):
        if time <= S[i]:
            time = C[i] + S[i]
        else:
            if time % F[i] != 0:
                time = time + C[i] + (F[i] - time % F[i])
            else:
                time = time + C[i]
    return time

for i in range(N-1):
    print(arrive(i))
print("0")


def main():
    with open(0) as f:
        N = int(f.readline())
        train = [tuple(map(int, line.split())) for line in f.readlines()]
    
    ans = []
    for start in range(N-1):
        arrive = 0
        for station in range(start, N-1):
            c, s, f = train[station]
            #出発時間:区間[arrive,)の下限     
            departure = lambda arrive:(arrive+f-1)//f*f if arrive >= s else s
            arrive = departure(arrive) + c
        ans.append(arrive)
    ans.append(0)
    for x in ans: print(x)

main()


n = int(input())
T = [0]*n
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
 
for i in range(n-1):
	c[i],s[i],f[i] = map(int,input().split())

for	i in range(n-1):
	T[i] = s[i] + c[i]
	for j in range(i+1,n-1):
		if T[i] > s[j]:
			T[i] = -((-T[i]//f[j]))*f[j] + c[j]
		else:
			T[i] = s[j] + c[j]
	print(T[i])
print(0)

n=int(input())
t=[]
for i in range(n-1):
  t.append(list(map(int,input().split())))


for i in range(n):
  s=0
  for j in range(i,n-1):
    s=max(t[j][1],((s-1)//t[j][2]+1)*t[j][2])+t[j][0]
  print(s)

N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] != 0:
            t += F[j]-t%F[j]
        t += C[j]
    print(t)

N = int(input())

x = []
for i in range(N - 1):
    c, s, f = list(map(int, input().split()))
    x.append([c, s, f])

ans = []
for i in range(N - 1):
    t = x[i][0] + x[i][1]
    for j in range(i + 1, N - 1):
        if t % x[j][2] == 0:
            t = max(t, x[j][1])
        else:
            t = max(t + (x[j][2] - t % x[j][2]), x[j][1])
        t += x[j][0]
    ans.append(t)
ans.append(0)

for i in range(N):
    print((ans[i]))


from math import ceil

n = int(input())
cs = []
ss = []
fs = []

for _ in range(n-1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)

for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t < ss[j]:
            t = ss[j]
        t = ceil(t / fs[j]) * fs[j]
        t += cs[j]
    print(t)

n = int(input())
csf = []
for i in range(n - 1):
    csf.append(list(map(int, input().split())))
for i in range(n):
    t = 0
    for j in range(n - i - 1):
        c, s, f = (csf[i + j][k] for k in range(3))
        t = (max(t - 1, s - 1) // f + 1) * f + c
    print(t)

N = int(input())
C = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        now = max(C[j][1], -(-now//C[j][2])*C[j][2])
        now += C[j][0]
    print(now)
print(0)

N = int(input())
CSF = [[] for T in range(0,N-1)]
for TN in range(0,N-1):
    CSF[TN] = [int(T) for T in input().split()]
for TN in range(0,N):
    Time = 0
    for TT in range(TN,N-1):
        if Time>=CSF[TT][1]:
            Time += CSF[TT][0] + (CSF[TT][2]-(Time%CSF[TT][2]))%CSF[TT][2]
        else:
            Time += CSF[TT][0] + (CSF[TT][1]-Time)
    print(Time)

N = int(input())
CSF = [ list(map(int,input().split(" "))) for _ in range(N - 1)]

for i in range(N):
    Time = 0
    for j in range(i, N - 1):
        c, s, f = CSF[j]
        Time = max(Time, s)
        if Time % f != 0:
            Time += (f - Time % f)
        Time += c

    print(Time)

n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  c_, s_ , f_ = map(int, input().split())
  c.append(c_)
  s.append(s_)
  f.append(f_)
  
for i in range(n-1):
  res = s[i] + c[i]
  for j in range(i+1, n-1):
    if res >= s[j]:
      if (res-s[j]) % f[j] == 0:
        res = res + c[j] + ((res - s[j]) % f[j])
      else:
        res = res + c[j] + f[j] - ((res-s[j])%f[j])
    else:
      res = s[j] + c[j]
  print(res)
print(0)

n = int(input())
graph =[]
time = 0
for i in range(n-1):
    c,s,f = map(int,input().split())
    graph.append([i,c,s,f])

def shortest_path(start,end,times):
    if start == end:
        return times
    elif times<=graph[start][2]:
        times = (graph[start][2]+graph[start][1])
        return shortest_path(start+1,end,times)
    elif times%graph[start][3]==0:
        times += (graph[start][1])
        return shortest_path(start+1,end,times)
    else:
        times = times+graph[start][3]-times%graph[start][3]+graph[start][1]
        return shortest_path(start+1,end,times)


for i in range(n):
    print(shortest_path(i,n-1,0))

n = int(input())
stations = []
for i in range(n-1):
    stations.append(list(map(int, input().split())))

ans = [0]
time_matrix = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i+1):
        if i < n-1:
            if time_matrix[i][j] % stations[i][2] == 0:
                waiting = 0
            else:
                waiting = stations[i][2] - (time_matrix[i][j] % stations[i][2])
            time_matrix[i+1][j] = max(time_matrix[i][j] + stations[i][0] + waiting, stations[i][0] + stations[i][1])

for i in range(n):
    print((time_matrix[n-1][i]))


n = int(input())
c_s_f = []
for i in range(n - 1):
    line = list(map(int, input().split()))
    c_s_f.append(line)

for i in range(n - 1):
    t = c_s_f[i][0] + c_s_f[i][1]
    for j in range(i + 1, n - 1):
        if t <= c_s_f[j][1]:
            t = c_s_f[j][1] + c_s_f[j][0]
        else:
            t = (t + c_s_f[j][2] - 1) // c_s_f[j][2] * \
                c_s_f[j][2] + c_s_f[j][0]
    print(t)
print((0))


n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
    time = 0
    while True:
        if i == n-1:
            print(time)
            break
        if time < csf[i][1]:
            time = csf[i][1] + csf[i][0]
        else:
            if time%csf[i][2] == 0:
                time += csf[i][0]
            else:
                time += csf[i][0] + csf[i][2] -  time%csf[i][2]
        i += 1


N=int(input())
C,S,F=map(list,zip(*[list(map(int,input().split())) for i in range(N-1)]))
r=[0]*N
for i in range(N-2,-1,-1):
    x=S[i]+C[i]
    for j in range(i+1,N-1):
        x=S[j]+C[j] if x<S[j] else -(-x//F[j])*F[j]+C[j]
    r[i]=x
print(*r,sep='\n')

N=int(input())
C=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    c,s,f=C[i]
    ans=s+c
    for j in range(i+1,N-1):
        nc,ns,nf=C[j]
        # print('D',ans,nc,ns,nf,(ans-ns)%nf)
        ans=max(ans,ns)
        m=(ans-ns)%nf
        if m!=0:ans+=nf-m
        # print('D',ans,nc,ns,nf,(ans-ns)%nf)
        ans+=nc
    print(ans)
print(0)

import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return list(map(int, stdin.readline().split()))
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    C = []
    S = []
    F = []
    for i in range(n - 1):
        c, s, f = nm()
        C.append(c)
        S.append(s)
        F.append(f)
    for i in range(n - 1):
        time = 0
        for j in range(i, n - 1):
            if time <= S[j]:
                time = S[j] + C[j]
            else:
                time = time + (F[j] - (time - S[j]) % F[j]) % F[j] + C[j]
        print(time)
    print((0))


def __starting_point():
    main()

__starting_point()

n = int(input())

C, S, F = [], [], []
for i in range(n-1):
    c,s,f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(n-1):
    # 各i駅から発車する列車をすべて調べる
    t = 0
    for j in range(i,n-1):
        if S[j]>t:
            t = S[j]
        
        if (t-S[j])%F[j]==0:
            t += C[j]
        else:
            t += F[j] - (t-S[j])%F[j] + C[j]

        if j==n-2:
            print(t)
print(0)

N=~-int(input())
C=[list(map(int,input().split())) for _ in range(N)]

for i in range(N):
 p,q,r=C[i]
 A=q+p
 for j in range(i+1,N):
  c,s,f=C[j]
  if A<s:A=s
  m=(A-s)%f
  if m!=0:A+=f-m
  A+=c
 print(A)
print(0)

# -*- coding: utf-8 -*-
"""
Created on Fri Oct  2 01:57:07 2020

@author: liang
"""
import math

N = int(input())
Stations = list()
for i in range(N-1):
    C, S, F = map(int,input().split())
    Stations.append((C,S,F))

def solve(n,time):
    if n == N-1:
        return time
    C, S, F = Stations[n]
    tmp = max(S+C, math.ceil(time/F)*F+C)
    return solve(n+1,tmp)

for i in range(N):
    print(solve(i,0))

n=int(input());A=[0]*n
for i in range(1,n):
  c,s,f=map(int,input().split())
  for j in range(i):A[j]=max(-A[j]//f*-f,s)+c
print(*A,sep="\n")

#!/usr/bin/env python

n = int(input())
c = [0 for _ in range(n-1)]
s = [0 for _ in range(n-1)]
f = [0 for _ in range(n-1)]
for i in range(n-1):
    c[i], s[i], f[i] = list(map(int, input().split()))

t = [[-1 for _ in range(n)] for _ in range(n-1)]

for i in range(n-1):
    t[i][i] = s[i]

for i in range(n-1):
    for j in range(i, n): 
        if i != j:
            t[i][j] = t[i][j-1]+c[j-1]
            if j == n-1:
                break
            if t[i][j]-t[j][j] <= 0:
                t[i][j] = t[j][j]
            else:
                if (t[i][j]-t[j][j])%f[j] != 0:
                    t[i][j] = t[j][j] + ((t[i][j]-t[j][j])//f[j]+1) * f[j]


#print('t =', t)

# output 
for i in range(n-1):
    print((t[i][n-1]))
print((0))


n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]
ans = []
for i in range(n-1):
    time = 0
    for p in range(i, n - 1):
        c, s, f = csf[p]
        if s >= time:
            time = s+c
        else:
            d = time - s
            time = s + f * (-(-d // f)) + c
    ans.append(time)

ans.append(0)

for i in range(n):
    print((ans[i]))


n = int(input())

now = 0
ans = [0] * (n)
CSF = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n - 1):
    now = 0
    for j in range(n - i - 1):
        c, s, f = CSF[i + j]
        if now <= s:
            now = s
        else:
            now = f * ((now + f - 1) // f)
        now += c
    ans[i] = now

print(("\n".join(map(str, ans))))


n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
    _c, _s, _f = list(map(int, input().split()))
    c.append(_c)
    s.append(_s)
    f.append(_f)

ans = 0

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        if ans < s[j]:
            ans = s[j] + c[j]
        elif ans % f[j] == 0:
            ans += c[j]
        else:
            ans += f[j] - ans%f[j] + c[j]

    print(ans)


N = int(input())
CSF = [[0] * 3 for i in range(N-1)]

for i in range(N-1):
    c, s, f = list(map(int, input().split()))
    CSF[i][0] = c
    CSF[i][1] = s
    CSF[i][2] = f

for i in range(N-1):
    now = CSF[i][1]+CSF[i][0]
    for j in range(i+1, N-1):
        # 1本目の前なら1本目まで待つ
        if now <= CSF[j][1]:
            now += CSF[j][0]+(CSF[j][1]-now)

        # 1本目以降なら待ち時間と移動時間を加算する
        else:
            while (now - CSF[j][1]) % CSF[j][2] != 0:
                now += 1
            now += CSF[j][0]
    print(now)
print((0))


n = int(input())
inp = []
for i in range(n-1):
    inp.append(list(map(int, input().split())))

for i in range(n-1):
    total = 0
    for j in range(i, n-1):
        if total < inp[j][1]:
            total = inp[j][1]
        while total % inp[j][2] != 0:
            total += 1
        total += inp[j][0]
    print(total)
print((0))
            





n=int(input())
yo=[]
for _ in range(n-1):
  a=list(map(int,input().split()))
  yo.append(a)
  
def ans(x):
  if x==n-1:
    return 0
  else:
    t=0
    for i in range(x,n-1):
      if t<=yo[i][1]:
        t=yo[i][1]+yo[i][0]
      else:
        s=t-yo[i][1]
        if s%yo[i][2]==0:
          t=t+yo[i][0]
        else:
          mo=s%yo[i][2]
          t=t+yo[i][2]-mo+yo[i][0]
    return t
    
for j in range(n):
  print((ans(j)))
        


N = int(input())
csf = [list(map(int,input().split())) for i in range(N-1)]
for i in range(N-1):
    ans = csf[i][1]+csf[i][0]
    for j in range(i+1,N-1):
        if ans <= csf[j][1]:
            ans = csf[j][1]
        else:
            f = ans%csf[j][2]
            if f != 0:
                ans += csf[j][2]-f
        ans += csf[j][0]
    print(ans)
print(0)

n=int(input())
l=[]
for _ in range(n-1):
  c,s,f=map(int,input().split())
  for i,t in enumerate(l):
    if t>s: t=-(-t//f)*f
    else: t=s
    l[i]=t+c
  l+=[s+c]
for i in l+[0]:
  print(i)

import math

n = int(input())
cL = []
sL = []
fL = []
for i in range(n - 1):
    c, s, f = map(int, input().split(" "))
    cL.append(c)
    sL.append(s)
    fL.append(f)

ans = 0
for i in range(n - 1):
    sm = 0
    for j in range(i, n - 1):
        c = cL[j]
        s = sL[j]
        f = fL[j]
        if sm < s:
            sm = s + c
            continue
        df = f - (sm - s) % f
        if df == f:
            df = 0
        sm += c + df
    print(sm)
print(0)

N=int(input())
csf=[list(map(int,input().split()))for _ in range(N-1)]
i=0
while i<N:
    ans=0
    j=i
    while j<N-1:
        c,s,f=list(csf[j])
        ans=max(ans,s)
        if ans%f:
            ans+=f-ans%f
        ans+=c
        j+=1
    print(ans)
    i+=1

N = int(input())
lis = [[0, 0, 1]]
for i in range(N - 1):
    C, S, F = list(map(int, input().split()))
    lis.append([C, S, F])

# i 駅スタート の電車
for i in range(N):
    C, S_ij, F = 0, 0, 1
    for j in range(i + 1, N):  # j 駅に着く
        C, S, F = lis[j]
        S = max(S, S_ij)  # max（j 駅のスタート時間、 ij 間の時間）
        S_ij = C + ((S - 1) // F + 1) * F
    print(S_ij)


def solve():
    n = int(input())
    csf = [list(map(int,input().split())) for _ in range(n-1)]
    
    for i in range(n):
        time = 0
        while True:
            if i == n-1:
                print(time)
                break
            if time < csf[i][1]:
                time = csf[i][1] + csf[i][0]
            else:
                if time%csf[i][2] == 0:
                    time += csf[i][0]
                else:
                    time += csf[i][0] + csf[i][2] -  time%csf[i][2]
            i += 1

def __starting_point():
    solve()
__starting_point()

N = int(input())
l = []
for i in range(N-1):
  c, s, f = map(int, input().split())
  l.append([c, s, f])
  
for i in range(N-1):
  time = l[i][1] + l[i][0]
  for j in range(i+1, N-1):
    if time-l[j][1] >= 0:
      wait = time % l[j][2]
      if wait == 0:
        time += l[j][0]
      else:
        time += l[j][2] - wait + l[j][0]
    else:
      time = l[j][1] + l[j][0]
  print(time)
print(0)

# import itertools
import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# from collections import deque
# import heapq

# 入力
N = int(input())
# S = input()
# n, *a = map(int, open(0))
# H, N = map(int, input().split())
# A = list(map(int, input().split()))
# A = list(map(lambda x: int(x)*(-1), input().split()))
# B = list(map(int, input().split()))
csf = [list(map(int,input().split())) for _ in range(N-1)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# edges = [list(map(int,input().split())) for _ in range(N - 1)]
# tree = [[] for _ in range(N + 1)]

# for edge in edges:
#     tree[edge[0]].append(edge[1])
#     tree[edge[1]].append(edge[0])

# depth = [-1] * (N + 1)
# depth[1] = 0
# count = [0] * (N + 1)

# for i in range(Q):
#     p, x = map(int, input().split())
#     count[p] += x

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + 1
#             dfs(tree, l[0])
# dfs(tree, 1)

# 素因数分解
# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

# 約数列挙
# def make_divisors(n):
#     lower_divisors , upper_divisors = [], []
#     i = 1
#     while i*i <= n:
#         if n % i == 0:
#             lower_divisors.append(i)
#             if i != n // i:
#                 upper_divisors.append(n//i)
#         i += 1
#     return lower_divisors + upper_divisors[::-1]

# bfs
# tree = [[] for _ in range(N + 1)]
# edges = [list(map(int,input().split())) for _ in range(M)]

# for edge in edges:
#     tree[edge[0]].append(edge[1])
#     tree[edge[1]].append(edge[0])

# depth = [-1] * (N + 1)
# depth[1] = 0

# d = deque()
# d.append(1)

# ans = [0] * (N + 1)
# while d:
#  v = d.popleft()
#  for i in tree[v]:
#    if depth[i] != -1:
#      continue
#    depth[i] = depth[v] + 1
#    ans[i] = v
#    d.append(i)

# # ans = depth[2:]
# print('Yes')
# print(*ans[2:], sep="\n")

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# # 高速素因数分解準備
# MAXN = 10**6+10
# sieve = [i for i in range(MAXN+1)]
# p = 2
# while p*p <= MAXN:
#     if sieve[p] == p:
#         for q in range(2*p, MAXN+1, p):
#             if sieve[q] == q:
#                 sieve[q] = p
#     p += 1


for i in range(N):
    t = 0
    for j in range(i, N - 1):
        if csf[j][1] >= t:
            t = csf[j][1] + csf[j][0]
            # print(i, j, t)
        else:
            t = csf[j][1] + math.ceil((t - csf[j][1]) / csf[j][2]) * csf[j][2] + csf[j][0]
            # print(i, j, t)
    print(t)

n=int(input())
c,s,f=[],[],[]
for _ in range(n-1):
    x,y,z=map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    temp=s[i]+c[i]
    for j in range(i+1,n-1):
        if temp<=s[j]: temp=s[j]+c[j]
        else:
            if (temp-s[j])%f[j]==0: temp+=c[j]
            else:
                k=(temp-s[j])//f[j]+1
                temp=s[j]+k*f[j]+c[j]
    print(temp)
print(0)

N= int(input())
li = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    ci,si,fi = li[i]
    time = si+ci
    for j in range(i+1,N-1):
        cj,sj,fj = li[j]
        if time%fj != 0:
            time = ((time//fj)+1)*fj
        #print(i,time)
        if time < sj:
            time = sj
        time += cj
    print(time)
print(0)

n = int(input())
C = []
S = []
F = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

def f(n, s, f):
    if n <= s:
        return s
    if n % f == 0:
        return n
    else:
        return n // f * f + f

for i in range(n-1):
    now = S[i] + C[i]
    for j in range(i+1, n-1):
        now = f(now, S[j], F[j]) + C[j]
    print(now)
print(0)

N=int(input())
l=[0]*N
for i in range(N-1):
 c,s,f=map(int,input().split())
 l[i]=c+s
 for j in range(i):
  l[j]=max(l[j],s,-(-l[j]//f)*f)+c

for i in l:print(i)

N=int(input())
CSF=[list(map(int,input().split())) for _ in range(N-1)]
for j in range(N):
    t=0
    for i in range(j,N-1):
        if t<CSF[i][1]:
            t=CSF[i][1]
        else:
            x=(t-1)//CSF[i][2]+1
            t=CSF[i][2]*x
        t+=CSF[i][0]
    print(t)


n = int(input())
cost = [0]*n
start = [0]*n
freaq = [0]*n
dp = [[0]*n for _ in range(n)]

for i in range(n-1):
    cost[i],start[i],freaq[i] = map(int,input().split())
    dp[i][i] = start[i]

freaq[n-1] = 1

t = 0

for i in range(n-1):
    for j in range(i+1):
        t = dp[j][i]
        t += cost[i]
        if t%freaq[i+1] != 0:
            t += freaq[i+1] - t%freaq[i+1]
        t = max(t,start[i+1])
        dp[j][i+1] = t

for i in range(n):
    print(dp[i][n-1])

n = int(input())
c = [0] * n
s = [0] * n
f = [0] * n
for i in range(n - 1):
    c[i], s[i], f[i] = map(int, input().split())

ans = [0] * n
for i in range(n - 1):
    for j in range(i, n - 1):
        if ans[i] < s[j]:
            ans[i] = s[j]
        elif ans[i] % f[j] > 0:
            ans[i] += f[j] - ans[i] % f[j]
        ans[i] += c[j]

for i in range(n):
    print(ans[i])

n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    t = 0
    for c,s,f in csf[i:]:
        if s > t:
            # 始発を待つ
            t = s
        else:
            # 次発を待つ
            t += (s-t) % f
        t += c
    print(t)
print(0)

N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
S.append(0)

import numpy as np
def theta(x): #ヘヴィサイドの段差関数
    return x if x > 0 else 0

def DptTimeAtNextSt(i, T): #時刻Tに駅iを出発した時、駅i+1を出発する時間
    nonlocal C, S, F
    arrT = T + C[i]
    if i == N-2: return arrT 
    return S[i+1] + np.ceil(theta(arrT-S[i+1])/F[i+1]) * F[i+1]

def solve(i, S): #駅iに対する解を再帰的に解く関数
    if i == N-1:
        return int(S)
    else:
        return solve(i+1, DptTimeAtNextSt(i,S))

for i in range(N):
    print(solve(i,S[i]))

n=int(input())
csf=[]
for i in range(n-1):
    c,s,f=list(map(int,input().split()))
    csf.append([c,s,f])

for i in range(n):
    t=0
    for j in range(i,n-1):
        c,s,f=csf[j]
        if t<=s:
            t = s + c
        else:
            if t%f==0: w=0
            else: w=f-t%f
            t = t + w + c
    print(t)


def jikan(now_t,i):
    if i==n:
        return now_t
    else:
        if now_t<=s[i]:
            now_t = s[i]
        else:
            tmp1 = now_t//f[i]
            if now_t%f[i]!=0:
                now_t = (tmp1+1)*f[i]
        tmp = jikan(now_t+c[i],i+1)
        return tmp

n = int(input())
c,s,f = [0],[0],[0]
for i in range(n-1):
    ci,si,fi = list(map(int,input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)
#print(c,s,f)
for i in range(1,n+1):
    print((jikan(0,i)))


from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
ls = []
for i in range(n-1):
    c, s, f = MAP()
    ls.append([c, s, f])
for i in range(n-1):
    ans = 0
    for j in range(i, n-1):
        ans = max(ans, ls[j][1])
        ans = ls[j][0] + ( ans + ls[j][2] - 1 )// ls[j][2] * ls[j][2]
    print(ans)
print(0)

#!/usr/bin/env python3
(n, ), *q = [[*map(int, i.split())] for i in open(0)]
ans = [0] * n
for i, p in enumerate(q):
    c, s, f = p
    for j in range(i):
        ans[j] = c + max(s, -(-ans[j] // f) * f)
    ans[i] = c + s
print(*ans, sep="\n")


N=int(input())
C=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
 c,s,f=C[i]
 A=s+c
 for j in range(i+1,N-1):
    nc,ns,nf=C[j]
    if A<ns:A=ns
    elif (A-ns)%nf!=0:A+=nf-(A-ns)%nf
    A+=nc
 print(A)
print(0)

import math
import sys


MAX_N = 500


N = int(input())
C = []
S = []
F = []
for _ in range(N - 1):
    c, s, f = [int(x) for x in input().split()]
    C.append(c)
    S.append(s)
    F.append(f)

if N == 1:
    print((0))
    return

for i in range(N - 1):
    t = S[i] + C[i]
    for j in range(i + 1, N - 1):
        t = max(S[j], int(math.ceil(t / F[j])) * F[j]) + C[j]
    print(t)
print((0))


N=int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
    CSF=list(map(int,input().split()))
    C.append(CSF[0])
    S.append(CSF[1])
    F.append(CSF[2])

ans=[0]*(N)

for i in range(N-1):
    t=0

    for j in range(i,N-1):
        m=-(-t//F[j])*F[j]
        t=max(S[j],m)
        t+=C[j]
    
    ans[i]=t

print(*ans,sep='\n')

import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    CSF = [NLI() for _ in range(N-1)]
    CSF.append([0,0,1])

    
    for n in range(N-1):
        time = CSF[n][1]
        
        for m in range(n,N-1):
            time += CSF[m][0]
            if time < CSF[m+1][1]:
                time = CSF[m+1][1]
            else:
                if time % CSF[m+1][2] != 0:
                    time = ((time//CSF[m+1][2])+1)*CSF[m+1][2]
        print(time)
    print(0)



def __starting_point():
    main()
__starting_point()

n = int(input())
timetable = [list(map(int, input().split())) for _ in range(n - 1)]

def nextstn(t, stn):
    if t >= timetable[stn][1]:
        return (((t + timetable[stn][2] - 1) // timetable[stn][2]) * timetable[stn][2]) + timetable[stn][0]
    else:
        return timetable[stn][1] + timetable[stn][0]

for i in range(n - 1):
    current_stn = i
    laps = 0
    while current_stn < n - 1:
        laps = nextstn(laps, current_stn)
        current_stn += 1
    print(laps)
else:
    print(0)

import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def cc(al):
	ret = 0
	for (c, s, f) in al:
		if ret <= s:
			ret = s+c
		else:
			st = ((ret + f-1)//f)*f
			ret = st + c
	print(ret)
		

def main():
	n = int(input())
	#if n==4:
	#	return 1/0
	#b , c = tin()
	#s = input()
	al = [lin() for _ in range(n-1)]
	for i in range(n):
		cc(al[i:])
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

def __starting_point():
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
__starting_point()

def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    #C:所要時間,S:開始後,F:間隔
    CSF = [list(map(int,input().split())) for _ in range(N-1)]

    for i in range(N):
        t = 0
        for c,s,f in CSF[i:]:
            if t<=s:
                t=s
            else:
                t=((t-s)//f if (t-s)%f==0 else (t-s)//f+1)*f+s
            t+=c
        print(t)

def __starting_point():
    main()
__starting_point()

N = int(input())
station = [list(map(int, input().split())) for _ in range(N - 1)]

lst = []

for i in range(N - 1):
    c, s, f = station[i]

    for j in range(len(lst)):
        a = lst[j]

        if a >= s:
            if a % f == 0:
                a += c
            else:
                a += (f - a % f) + c
        else:
            a = s + c

        lst[j] = a

    lst.append(s + c)


lst.append(0)
for a in lst:
    print(a)


N=int(input())
CSF=[list(map(int,input().split())) for _ in range(N-1)]
for j in range(N):
    t=0
    for i in range(j,N-1):
        if t<CSF[i][1]:
            t=CSF[i][1]
        else:
            x=(t-1)//CSF[i][2]+1
            t=CSF[i][2]*x
        t+=CSF[i][0]
    print(t)

def resolve():
    '''
    code here
    '''
    N = int(input())
    starts = [[int(item) for item in input().split()] for _ in range(N-1)]

    for i in range(N):
        temp_time = 0
        if i == N-1:
            print((0))
        else:
            for j in range(i,N-1):
                c, s, f = starts[j]
                if temp_time <= s:
                    temp_time = s

                if temp_time % f == 0:
                    pass
                else:
                    temp_time = (temp_time // f + 1) * f
            
                temp_time += c
            print(temp_time)


def __starting_point():
    resolve()

__starting_point()

N = int(input())
T = 0
t = 0
ans = []
for i in range(N-1):
    C, S, F = list(map(int, input().split()))
    for j in range(len(ans)):
        if ans[j] <= S:
            ans[j] = S+C
        elif ans[j]%F != 0:
            ans[j] = ans[j]+F-(ans[j] % F)+C
        else:
            ans[j] += C
    ans.append(S+C)
for a in ans:
    print(a)
print((0))


N = int(input())
C, S, F = [], [], []

for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for station in range(N):
    now = station
    time = 0

    while now < N-1:
        if time < S[now]:
            time = S[now] + C[now]
        else:
            if time % F[now] == 0:
                time += C[now]
            else:
                wait_time = F[now] - (time % F[now])
                time += wait_time + C[now]

        now += 1

    print(time)

n=int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]
ans1=[]
for j in range(n-1):
  requ_time=csf[j][1]+csf[j][0]
  for i in range(j,n-1):
    if i!=j:
      if requ_time <= csf[i][1]:
        requ_time+=(csf[i][0]+(csf[i][1]-requ_time))
  #elif requ_time > csf[i][1] and csf[i][0]+csf[1] > requ_time:
      else:
        requ_time+=(csf[i][0]+(csf[i][2]-(requ_time-csf[i][1])%csf[i][2])%csf[i][2])
  ans1.append(requ_time)
for i in ans1:
  print(i)
print((0))


n=int(input())
l=[0]*n
for i in range(1,n):
  c,s,f=map(int,input().split())
  for j in range(i):
    l[j]=max(-l[j]//f*-f,s)+c
for i in l: print(i)

import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = stations[j]
        if t <= s:
            t = s + c
        else:
            tmp = t - s
            t = s + f * ((tmp - 1) // f + 1) + c

    print(t)
print(0)

import math
def main():
    n=int(input())
    csf=[list(map(int,input().split())) for _ in range(n-1)]
    for i in range(n):
        if i == n-1:
            print(0)
        else:
            t=0
            for c,s,f in csf[i:]:
                t = max(s,t)
                t = math.ceil(t/f)*f+c
                #print("start:", i, t)
            print(t)

def __starting_point():
    main()
__starting_point()

N = int(input())
csf = [list(map(int, input().split())) for _ in range(N-1)]
ans = [None]*N
ans[-1] = 0
for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if now <= csf[j][1]:
            now = csf[j][1]
        else:
            t  = (now - csf[j][1] + csf[j][2]-1)//csf[j][2]
            now = csf[j][1] + t*csf[j][2]
        now += csf[j][0]
    ans[i] = now
[print(a) for a in ans]

N = int(input())
csf = [list(map(int, input().split())) for i in range(N - 1)]

for i in range(N):
    ans = 0
    for c, s, f in csf[i::]:
        if ans <= s:
            ans = s
        else:
            if ans % f == 0:
                pass
            else:
                ans = (ans // f + 1) * f
        ans += c
    print(ans)


def est_time(sta,N,csf_list):
  SUM = 0
  for i in range(sta,N):
    if i == sta:
      SUM += csf_list[i-1][0] + csf_list[i-1][1]
    else:
      if SUM >= csf_list[i-1][1]:
        SUM = ((SUM+csf_list[i-1][2]-1) // csf_list[i-1][2])*csf_list[i-1][2]
        SUM += csf_list[i-1][0]
      else:
        SUM = csf_list[i-1][1]
        SUM += csf_list[i-1][0]
  return SUM

N=int(input())
csf_list=[tuple(map(int,input().split())) for _ in range(N-1)]

for i in range(N):
  print(est_time(i+1,N,csf_list))

N = int(input())
Cls = [0]
Sls = [0]
Fls = [0]
lsans = []
for i in range(1,N):
    c,s,f = map(int,input().split())
    Cls.append(c)
    Sls.append(s)
    Fls.append(f)
for i in range(1,N):
    t = 0
    for j in range(i,N):
        if t < Sls[j]:
            t = Sls[j] + Cls[j]
        elif t%Fls[j] == 0:
            t += Cls[j]
        else:
            t += Fls[j]-(t%Fls[j])+Cls[j]
    lsans.append(t)
lsans.append(0)
for i in lsans:
    print(i)

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *CSF = map(int, read().split())
    train = [0] * (N - 1)
    for i, t in enumerate(zip(*[iter(CSF)] * 3)):
        train[i] = t

    ans = [0] * N
    for i in range(N - 1):
        t = 0
        for c, s, f in train[i:]:
            if t < s:
                t = s + c
            else:
                t += f - ((t - 1) % f + 1) + c
        ans[i] = t

    ans[N - 1] = 0
    print(*ans, sep='\n')
    return


def __starting_point():
    main()

__starting_point()

import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = stations[j]
        if t <= s:
            t = s + c
        else:
            tmp = t - s
            t = s + f * ((tmp - 1) // f + 1) + c

    print(t)
print(0)

#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**6)
n = int(input())

csf = [list(map(int, input().split())) for i in range(n-1)]

for i in range(n-1):
    csf_tmp = csf[i:]

    c, s, f = csf_tmp[0]

    t = c+s
    for j in range(1, len(csf_tmp)):
        c, s, f = csf_tmp[j]

        if t <= s:
            t = s
        else:
            mod = (t-s) % f
            if mod != 0:
                t += f-mod
        # print(t)
        t += c
        # print(t)
    print(t)
    # print()
print((0))


n = int(input())
ans = [0] * n

for i in range(1, n):
    c, s, f = list(map(int, input().split()))

    for j in range(i):
        ans[j] = max(ans[j], s)
        ans[j] = ((ans[j]+f-1)//f) * f
        ans[j] += c

for a in ans:
    print(a)

n = int(input())
route, ans = [], []
for i in range(n-1):
    a = list(map(int, input().split()))
    route.append(a)

for i in range(n-1):
    c = route[i][0]+route[i][1]
    for j in range(i+1, n-1):
        if c < route[j][1]:
            c = route[j][0]+route[j][1]
        elif (c-route[j][1])%route[j][2] == 0:
            c += route[j][0]
        else:
            c += route[j][0]+route[j][2]-(c-route[j][1])%route[j][2]
    ans.append(c)
ans.append(0)
for i in ans:
    print(i)


N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for TN in range(0,N-1):
    C[TN],S[TN],F[TN] = (int(T) for T in input().split())
for TN in range(0,N):
    Time = 0
    for TS in range(TN,N-1):
        if Time>=S[TS]:
            Time += C[TS]+(F[TS]-(Time%F[TS]))%F[TS]
        else:
            Time += C[TS]+(S[TS]-Time)
    print(Time)

n = int(input())
T = [0]*n
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
 
for i in range(n-1):
	c[i],s[i],f[i] = map(int,input().split())

for	i in range(n-1):
	T[i] = s[i] + c[i]
	for j in range(i+1,n-1):
		if T[i] > s[j]:
			T[i] += (-T[i])%f[j] + c[j]
		else:
			T[i] = s[j] + c[j]
	print(T[i])
print(0)

from math import *

n = int(input()) - 1
c = [0] * n
s = [0] * n
f = [0] * n
for i in range(n):
  c[i], s[i], f[i] = map(int, input().split())
  
for i in range(n):
  a = s[i] + c[i]
  for j in range(i + 1, n):
    if a <= s[j]:
      a = s[j] + c[j]
    else:
      a = s[j] + f[j] * ceil((a-s[j])/f[j]) + c[j]
  print(a)
print(0)

n=int(input())
csf=[tuple(map(int,input().split())) for _ in range(n-1)]

arrtime=lambda i,cs: max(csf[i][2]*(cs//csf[i][2]+(cs%csf[i][2]>0)),csf[i][1])+csf[i][0]
for i in range(n-1):
  arrivN=csf[i][1]
  for j in range(i,n-1):
    arrivN=arrtime(j,arrivN)
  print(arrivN)
print(0)

n = int(input())
cl = []
sl = []
fl = []

for _ in range(n-1):
    c,s,f = list(map(int,input().split()))
    cl += [c]
    sl += [s]
    fl += [f]

        

for i in range(n):
    time = 0
    while True:
        if i==n-1:
            print(time)
            break
        if sl[i]<=time and time%fl[i]==0:
            time += cl[i]
        elif sl[i]>time:
            time = sl[i] +cl[i]
        else: #sl[i]<=time and time%fl[i]!=0
            time += fl[i] - time%fl[i] +cl[i]
        i += 1
    



n=int(input())
num=[]
for i in range(n-1):
    num.append(list(map(int,input().split())))
for i in range(n-1):
    ans=0
    for j in range(i,n-1):
        if ans<=num[j][1]:
            ans=num[j][1]
        else:
            ans=num[j][1]+((-((ans-num[j][1])//-num[j][2]))*num[j][2])
        ans+=num[j][0]
    print(ans)
print((0))


N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int,input().split())

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)

#!/usr/bin/env python
# coding: utf-8

# In[18]:


N = int(input())
csf = []
for _ in range(N-1):
    csf.append(list(map(int, input().split())))


# In[19]:


for i in range(N):
    if i < N-1:
        t = csf[i][1]
        for i in range(i,N-1):
            c,s,f = csf[i]
            if t >= s:
                if t%f == 0:
                    t += c
                else:
                    t = (-(-t//f))*f+c
            else:
                t = s+c
        print(t)
    else:
        print((0))


# In[ ]:






import math
N = int(input())

C = []
S = []
F = []
for _ in range(N - 1):
    c, s, f = list(map(int, input().split()))
    C.append(c)
    S.append(s)
    F.append(f)


for i in range(N - 1):
    count = 0
    count += S[i]
    count += C[i]
    for j in range(i + 1, N - 1):
        if count < S[j]:
            count = S[j]
        else:
            count = math.ceil((count - S[j]) / F[j]) * F[j] + S[j]
        count += C[j]
    print(count)
print((0))


n = int(input())
ls = [list(map(int,input().split())) for _ in range(n-1)]
def culc(nt,p):
    if nt == 0:
        if p != n-1:
            nt = ls[p][1] + ls[p][0]
            culc(nt,p+1)
        else:
            print((0))
    else:
        if p != n-1:
            if nt >= ls[p][1]:
                m = (nt - ls[p][1])//ls[p][2]
                if (nt - ls[p][1])%ls[p][2] != 0:
                    m += 1
                nt = ls[p][1] + ls[p][2]*m + ls[p][0]
                culc(nt,p+1)
            else:
                nt = ls[p][1] + ls[p][0]
                culc(nt,p+1)
        else:
            print(nt)
for i in range(n):
    culc(0,i)



import math

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N):
    t = 0

    for c, s, f in CSF[i:]:
        # 待ち時間
        if t < s:
            t = s
        else:
            t = math.ceil((t - s) / f) * f + s

        # i -> i+1に移動
        t += c

    print(t)


import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())
A=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    if i==n-1:print((0));return
    now=0
    for l in A[i:]:
        c,s,f =l 
        now=max(now,s)
        for plus in range(0,101):
            if (now+plus)% f==0:
                now+=plus
                break
        now+=c
    print(now)



n = int(input())
csf = [tuple(map(int, input().split())) for _ in range(n - 1)]

for i in range(n - 1):
    c, s, f = csf[i]
    a = s + c
    now = i
    for j in range(i + 1, n - 1):
        nc, ns, nf = csf[j]
        # next = ns + nf * x
        if a <= ns:
            a = ns
        else:
            x = (a - ns + nf - 1) // nf
            a = ns + nf * x
        a += nc

    print(a)
print((0))


n=int(input())
C=[]
S=[]
F=[]
for i in range(n-1):
	c,s,f=list(map(int, input().split()))
	C.append(c)
	S.append(s)
	F.append(f)

def d(x,t): #駅x時間ｔで移動するのにかかる時間
	if S[x]>=t:
		return C[x]+S[x]-t
	else:
		if (t-S[x])%F[x]==0:
			return C[x]
		else:
			return C[x]+F[x]-(t-S[x])%F[x]

for i in range(n-1):
	x=i
	ans=0
	for j in range(x,n-1):
		ans+=d(j,ans)
		x=+1
	print(ans)
print((0))