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: EASY

Solutions:
n = int(input())
(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):
	d = c[i] + s[i]
	for j in range(i + 1, n - 1):
		d = max(((d - s[j] - 1) // f[j] + 1) * f[j] + s[j], s[j]) + c[j]
	print(d)
print(0)


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())
dia = []
for _ in range(N - 1):
	(c, s, f) = map(int, input().split())
	dia.append((c, s, f))
for i in range(N - 1):
	time = 0
	for j in range(i, N - 1):
		(c, s, f) = dia[j]
		while time > s:
			s += f
		time = s + c
	print(time)
print(0)


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)


import sys
input = sys.stdin.readline

def f():
	n = int(input())
	l = tuple((tuple(map(int, input().split())) for i in range(n - 1)))
	for i in range(n):
		now = 0
		for (a, s, d) in l[i:]:
			if now <= s:
				now = s + a
			else:
				now = -(-now // d) * d + a
		print(now)
f()


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
		elif ans % f == 0:
			pass
		else:
			ans = (ans // f + 1) * f
		ans += c
	print(ans)


import math

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


n = int(input())
times = [0]
for i in range(n - 1):
	(c, s, f) = map(int, input().split())
	for (j, t) in enumerate(times):
		now = max(t, s)
		times[j] = now + (f - now) % f + c
	times.append(0)
for t in times:
	print(t)


n = int(input())
(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):
	ans = s[i] + c[i]
	for j in range(i + 1, n - 1):
		if s[j] > ans:
			ans = s[j] + c[j]
		else:
			ans += (f[j] - ans % f[j]) % f[j] + c[j]
	print(ans)
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
		if time < sj:
			time = sj
		time += cj
	print(time)
print(0)


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


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 - 1):
	ans = 0
	for j in range(i, n - 1):
		ans = max((ans + F[j] - 1) // F[j] * F[j], S[j]) + C[j]
	print(ans)
print(0)


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]
		ans = max(ans, ns)
		m = (ans - ns) % nf
		if m != 0:
			ans += nf - m
		ans += nc
	print(ans)
print(0)


N = int(input())
c = [list(map(int, input().split())) for _ in range(N - 1)]
for j in range(N):
	nowt = 0
	for i in range(j, N - 1):
		f = c[i][2]
		nowt = max(c[i][1], (nowt + f - 1) // f * f) + c[i][0]
	print(nowt)


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)


import math
N = int(input())
A = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
	t = 0
	for (C, S, F) in A[i:]:
		if t < S:
			t = S + C
		else:
			t = math.ceil((t - S) / F) * F + S + C
	print(t)


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)


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


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)


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):
	if S[x] >= t:
		return C[x] + S[x] - t
	elif (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)


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


import sys
mod = 10 ** 9 + 7
inf = float('inf')
from math import sqrt, ceil
from collections import deque, Counter, defaultdict
input = lambda : sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP, Decimal
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
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())
l = [list(map(int, input().split())) for i in range(n - 1)]
for j in range(n):
	c = 0
	for k in range(j, n - 1):
		if l[k][1] >= c:
			c = l[k][1] + l[k][0]
		else:
			c = l[k][1] + ((c - l[k][1] - 1) // l[k][2] + 1) * l[k][2] + l[k][0]
	print(c)


n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for j in range(n):
	time = 0
	for i in range(j, n - 1):
		if time > csf[i][1]:
			time += (csf[i][1] - time) % csf[i][2]
		else:
			time = csf[i][1]
		time += csf[i][0]
	print(time)


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


N = int(input())
li = []
for index in range(N - 1):
	(c, s, f) = map(int, input().split())
	li.append((c, s, f))
for i in range(N):
	t = 0
	station = i
	while station < N - 1:
		(c, s, f) = li[station]
		if t < s:
			t = s
			t += c
		else:
			t += (f - (t - s)) % f + c
		station += 1
	print(t)


N = int(input())
CSF = [None] * (N - 1)
for i in range(N - 1):
	CSF[i] = list(map(int, input().split()))
for I in range(N):
	now = 0
	for csf in CSF[I:]:
		now = max(-(-now // csf[2]) * csf[2], csf[1]) + csf[0]
	print(now)


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)


import math
N = int(input())
C = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	total = 0
	for j in range(i, N - 1):
		total = max(math.ceil(total / C[j][2]) * C[j][2], C[j][1])
		total += C[j][0]
	print(total)
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)


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))


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]
		elif 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())
a = []
for i in range(n - 1):
	(x, y, z) = map(int, input().split())
	a.append([x, y, z])
for i in range(n):
	t = 0
	for j in range(i, n - 1):
		if t <= a[j][1]:
			t = a[j][1] + a[j][0]
		else:
			t = (t - a[j][1] + a[j][2] - 1) // a[j][2] * a[j][2] + a[j][1] + a[j][0]
	print(t)


N = int(input())
A = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N):
	t = 0
	for j in range(i, N - 1):
		if t < A[j][1]:
			t = A[j][1]
		elif (t - A[j][1]) % A[j][2]:
			t += A[j][2] - t % A[j][2]
		t += A[j][0]
	print(t)


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


N = int(input())
stations = [tuple(map(int, input().split(' '))) for _ in range(N - 1)]
for i in range(N - 1):
	t = 0
	for j in range(i, N - 1):
		(c, s, f) = stations[j]
		t = max(t, s)
		if t % f != 0:
			t += f - t % f
		t += c
	print(t)
print(0)


n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
	(ci, si, fi) = map(int, input().split())
	c.append(ci)
	s.append(si)
	f.append(fi)
for i in range(n):
	ans = 0
	for j in range(i, n - 1):
		if ans < s[j]:
			ans = s[j]
		ans = (ans + f[j] - 1) // f[j] * f[j] + c[j]
	print(ans)


def resolve():
	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())
a = []
for i in range(n - 1):
	(c, s, f) = map(int, input().split())
	a.append([c, s, f])
ans = 0
while len(a) > 0:
	ans = 0
	for (i, j, k) in a:
		ans = max(ans, j)
		if ans % k != 0:
			ans += k - ans % k
		ans += i
	print(ans)
	a.pop(0)
print(0)


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:
			if t % f:
				t += f - t % f
		else:
			t = s
		t += c
	print(t)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n - 1)]
(*a,) = zip(*a)
(c, s, f) = (a[0], a[1], a[2])
for l in range(n):
	t = 0
	for k in range(n - 1 - l):
		t = s[l + k] + (max(0, t - s[l + k]) + f[l + k] - 1) // f[l + k] * f[l + k] + c[l + k]
	print(t)


n = int(input())
CSF = [tuple(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
		elif t % f != 0:
			t += f - t % f
		t += c
	print(t)


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


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)


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
		t += c
	print(t)
print(0)


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


N = int(input())
T = [list(map(int, input().split())) for k in range(N - 1)]
for k in range(N):
	t = 0
	for i in range(k, N - 1):
		if t < T[i][1]:
			t = T[i][0] + T[i][1]
		else:
			t += T[i][0] + (T[i][2] - t % T[i][2]) % T[i][2]
	print(t)


n = int(input())
CSF = [list(map(int, input().split())) for _ in range(n - 1)]
Ans = []
from math import ceil
count = 0
for (c, s, f) in CSF:
	for i in range(count):
		Ans[i] = max(ceil(Ans[i] / f) * f + c, s + c)
	count += 1
	Ans.append(s + c)
print(*Ans, sep='\n')
print(0)


N = int(input())
CSF = [tuple(map(int, input().split())) for _ in range(N - 1)]
for st in range(N):
	t = 0
	for i in range(st, N - 1):
		(C, S, F) = CSF[i]
		k = max(0, (t - S + F - 1) // F)
		t = S + F * k + C
	print(t)


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


n = int(input())
l = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n - 1):
	t = l[i][1]
	t += l[i][0]
	for j in range(i + 1, n - 1):
		if t < l[j][1]:
			t = l[j][1]
		elif t % l[j][2] != 0:
			t += l[j][2] - t % l[j][2]
		t += l[j][0]
	print(t)
print(0)


import math
N = int(input())
csf = [list(map(int, input().split())) for _ in range(N - 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]
		else:
			t = csf[j][1] + math.ceil((t - csf[j][1]) / csf[j][2]) * csf[j][2] + csf[j][0]
	print(t)


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 = [0] * N
S = [0] * N
F = [0] * (N - 1)
F.append(1)
for i in range(N - 1):
	(C[i], S[i], F[i]) = map(int, input().split())
for i in range(N):
	time = S[i]
	for j in range(i, N):
		time = max((F[j] - (time - S[j])) % F[j] + time, S[j]) + C[j]
	print(time)


from itertools import accumulate
(n, *l) = map(int, open(0).read().split())
c = l[::3]
s = l[1::3]
f = l[2::3]

def func(m):
	t = c[m] + s[m]
	for i in range(m + 1, n - 1):
		fi = f[i]
		t = max((t // fi + (t % fi != 0)) * fi, s[i]) + c[i]
	return t
for i in range(n - 2):
	print(func(i))
print(c[-1] + s[-1], 0, sep='\n')


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


n = int(input())
CSF = [list(map(int, input().split())) for _ in range(n - 1)]
(C, S, F) = zip(*CSF)
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]:
			t += F[j] - t % F[j]
		t += C[j]
	print(t)


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])
for i in range(N):
	(C, S_ij, F) = (0, 0, 1)
	for j in range(i + 1, N):
		(C, S, F) = lis[j]
		S = max(S, S_ij)
		S_ij = C + ((S - 1) // F + 1) * F
	print(S_ij)


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())
x = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
	ans = 0
	for j in range(i, n - 1):
		if ans % x[j][2] == 0:
			a = 0
		else:
			a = x[j][2] - ans % x[j][2]
		ans = max(ans + a, x[j][1])
		ans += x[j][0]
	print(ans)


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)


import math
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):
	ans = 0
	for j in range(i, n - 1):
		ans = max(s[j], math.ceil(ans / f[j]) * f[j]) + c[j]
	print(ans)


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)


N = int(input())
csf = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
	t = 0
	for j in range(i, N - 1):
		(C, S, F) = csf[j]
		if t < S:
			t = S
		elif t % F:
			t = t + F - t % F
		t += C
	print(t)


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


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

def t(x, k):
	if a[k][1] <= x:
		return (x + a[k][2] - 1) // a[k][2] * a[k][2] + a[k][0]
	return a[k][1] + a[k][0]
for i in range(n - 1):
	p = t(0, i)
	for j in range(i + 1, n - 1):
		p = t(p, j)
	print(p)
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())
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())
csf = [[int(x) for x in input().split()] for _ in range(N - 1)]
from math import ceil

def f(t, i):
	for j in range(i, N - 1):
		(c, s, f) = csf[j]
		(d, m) = divmod(t, f)
		t = max(s, ceil(t / f) * f) + c
	return t
for i in range(N):
	print(f(0, i))


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


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())
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):
	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)


n = int(input())
l = [list(map(int, input().split())) for i in range(n - 1)] + [[0, 0, 1]]
al = []
mati = 0
for i in range(n):
	now = l[i][1] + l[i][0]
	for j in range(i + 1, n):
		now = l[j][0] + l[j][1] - -max(0, now - l[j][1]) // l[j][2] * l[j][2]
	al.append(now)
print(*al, sep='\n')


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):
	t = 0
	for j in range(i, n - 1):
		(c, s, f) = l[j]
		while t > s:
			s += f
		t = s + c
	print(t)
print(0)


import math
n = int(input())
csf = [input() for _ in range(n - 1)]
for i in range(n - 1):
	(c, s, f) = map(int, csf[i].split())
	cost = s + c
	for j in range(i + 1, n - 1):
		(c, s, f) = map(int, csf[j].split())
		cost = math.ceil((cost - s) / f) * f + s + c if cost > s else s + c
	print(cost)
print(0)


n = int(input())
a = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
	time = 0
	for j in range(i, n - 1):
		(t, s, f) = a[j]
		if time < s:
			time = s
		elif time % f == 0:
			time = time
		else:
			time = time + f - time % f
		time += t
	print(time)


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])


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()


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())
	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
	ret = main()
	if ret is not None:
		print(ret)
__starting_point()


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())
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)


from math import ceil
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	ans = 0
	for j in range(i, n - 1):
		(c, s, f) = csf[j]
		ans = c + max(s, f * ceil(ans / f))
	print(ans)


((n,), *d) = [list(map(int, c.split())) for c in open(0)]
n -= 1
for i in range(n):
	t = 0
	for j in range(i, n):
		(c, s, f) = d[j]
		t = (s if t < s else t if t % f == 0 else t + f - t % f) + c
	print(t)
print(0)


n = int(input())
l = []
for i in range(n - 1):
	l.append(list(map(int, input().split())))
for i in range(n - 1):
	t = l[i][0] + l[i][1]
	for j in range(i + 1, n - 1):
		if t < l[j][1]:
			t = l[j][0] + l[j][1]
		else:
			m = t % l[j][2]
			t += l[j][0] + (l[j][2] - m) * (m != 0)
	print(t)
print(0)


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]
		elif 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')


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 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())
train = [list(map(int, input().split())) for i in range(N - 1)]
anslist = [0]
for i in range(N - 1):
	ans = 0
	for j in range(i, N - 1):
		ans = max(train[j][1], ans)
		ans = ((ans - 1) // train[j][2] + 1) * train[j][2]
		ans += train[j][0]
	print(ans)
print(0)


N = int(input())
src = [tuple(map(int, input().split())) for i in range(N - 1)]
anss = []
for i in range(N - 1):
	now = 0
	for (c, s, f) in src[i:]:
		if now < s:
			now = s
		now += (f - now % f) % f + c
	anss.append(now)
anss.append(0)
print(*anss, sep='\n')


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):
	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):
	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())
ary = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	t = 0
	for j in range(i, n - 1):
		if t <= ary[j][1]:
			t = ary[j][1]
		elif t % ary[j][2] == 0:
			t += 0
		else:
			t += ary[j][2] - t % ary[j][2]
		t += ary[j][0]
	print(t)


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, *t) = map(int, open(0).read().split())
for i in range(n):
	a = 0
	for (c, s, f) in zip(t[3 * i::3], t[3 * i + 1::3], t[3 * i + 2::3]):
		a = max(s, a // -f * -f) + c
	print(a)


import math
n = int(input())
csf = [list(map(int, input().split())) for i in range(n - 1)]
ANS = []
for i in range(n):
	ans = 0
	for (c, s, f) in csf[i:]:
		if ans <= s:
			ans = s + c
		else:
			ans = s + math.ceil((ans - s) / f) * f + c
	ANS.append(ans)
for i in ANS:
	print(i)


n = int(input())
vec = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	t = 0
	for j in range(i, n - 1):
		(ci, si, fi) = vec[j]
		if t <= si:
			t = si
		else:
			t = (t + fi - 1) // fi * fi
		t += ci
	print(t)


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


N = int(input())
dp = [0] * N
for i in range(N - 1):
	(C, S, F) = map(int, input().split())
	for j in range(i + 1):
		if dp[j] > S:
			if (dp[j] - S) % F != 0:
				dp[j] = ((dp[j] - S) // F + 1) * F + S
		else:
			dp[j] = S
		dp[j] += C
for i in range(N):
	print(dp[i])


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):
	ans = 0
	for j in range(i, n - 1):
		ans = max(s[j], (ans + f[j] - 1) // f[j] * f[j])
		ans += c[j]
	print(ans)


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())
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:
			time += fl[i] - time % fl[i] + cl[i]
		i += 1


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

def ceil(x, y):
	return (x - 1) // y + 1
for i in range(N - 1):
	n = 0
	for j in range(i, N - 1):
		(c, s, f) = CSF[j]
		if n <= s:
			n = s
		n = s + ceil(n - s, f) * f + c
	print(n)
print(0)


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


import math
N = int(input())
A = [list(map(int, input().split())) for _ in range(N - 1)]
A.insert(0, 0)
for i in range(1, N):
	(C, S, F) = A[i]
	T = S + C
	j = i + 1
	while j < N:
		(C, S, F) = A[j]
		T = max(S, math.ceil(T / F) * F)
		T += C
		j += 1
	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 math
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	ans = 0
	for j in range(i, n - 1):
		(c, s, f) = map(lambda x: x, csf[j])
		if ans <= s:
			ans = s + c
		else:
			ans = math.ceil(ans / f) * f + c
	print(ans)


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


import math
n = int(input())
x = []
for k in range(n - 1):
	(a, b, c) = [int(i) for i in input().split(' ')]
	x = [max(math.ceil((j - b) / c) * c + b, b) + a for j in x]
	x.append(a + b)
x.append(0)
for i in range(n):
	print(x[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) = ([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())
arr = [0] * n
for i in range(n - 1):
	for j in range(i, n - 1):
		l = s[j]
		if arr[i] > l:
			while arr[i] > l:
				l += f[j]
		arr[i] = l
		arr[i] += c[j]
	print(arr[i])
print(0)


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


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]
			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()


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)
for i in range(1, n + 1):
	print(jikan(0, i))


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]
			elif 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())
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)
	elif 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)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	t = 0
	for (c, s, f) in a[i:]:
		k = max(0, (t - s + f - 1) // f)
		t = s + f * k + 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())
c = []
for i in range(n - 1):
	(x, y, z) = map(int, input().split())
	c.append((x, y, z))
for i in range(n - 1):
	ans = 0
	for j in range(i, n - 1):
		ans = [c[j][1] + (ans - c[j][1] + c[j][2] - 1) // c[j][2] * c[j][2], c[j][1]][ans < c[j][1]]
		ans += c[j][0]
	print(ans)
ans = chk = 0
print(ans)


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())
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

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(t)

def __starting_point():
	main()
__starting_point()


N = int(input())
(C, S, F) = zip(*[tuple(map(int, input().split())) for _ in range(N - 1)])
S = list((s for s in S)) + [0]
for i in range(N - 1):
	for j in range(i, N - 1):
		S[i] = max(S[i], S[j])
		while S[i] % F[j]:
			S[i] += 1
		S[i] += C[j]
print(*S, sep='\n')


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


def main():
	import sys
	input = lambda : sys.stdin.readline().strip()
	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 = ((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())
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]
		elif 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())
X = []
for _ in range(N - 1):
	(c, s, f) = map(int, input().split())
	X.append((c, s, f))
for k in range(N):
	t = 0
	for i in range(k, N - 1):
		(c, s, f) = X[i]
		t = -(-t // f) * f
		t = max(t, s)
		t += c
	print(t)


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

def get(i):
	ans = 0
	for (c, s, f) in csf[i:]:
		ans = max(ans, s)
		ans = (ans + f - 1) // f * f
		ans += c
	return ans
for i in range(n):
	print(get(i))


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):
		if now <= CSF[j][1]:
			now += CSF[j][0] + (CSF[j][1] - now)
		else:
			while (now - CSF[j][1]) % CSF[j][2] != 0:
				now += 1
			now += CSF[j][0]
	print(now)
print(0)


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


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


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

def GT(k, t):
	(c, s, f) = (TTBL[k][0], TTBL[k][1], TTBL[k][2])
	return s + max(0, t - s + (f - 1)) // f * f + c
for i in range(N - 1):
	ret = 0
	for j in range(i, N - 1):
		ret = GT(j, ret)
	print(ret)
print(0)


n = int(input())
train = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	t = 0
	for j in range(i, n - 1):
		(c, s, f) = train[j]
		t = max(t, s)
		t += (f - t % f) % f
		t += c
	print(t)


N = int(input())
csf = [tuple(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 + C
		elif t == S or t % F == 0:
			t += C
		else:
			t += F - t % F + C
	print(t)


N = int(input())
src = [tuple(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	time = 0
	for (c, s, f) in src[i:]:
		if time <= s:
			time = s + c
		else:
			time += (f - (time - s)) % f + c
	print(time)
print(0)


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())
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())
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)


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()) - 1
stations = []
for i in range(N):
	stations.append(tuple(map(int, input().split())))

def helper(t, i):
	(c, s, f) = stations[i]
	n = max((t - s - 1) // f + 1, 0)
	return s + f * n + c
for s in range(N):
	t = 0
	for i in range(s, N):
		t = helper(t, i)
	print(t)
print(0)


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)


from math import ceil
n = int(input())
cur = [0] * n
for i in range(n - 1):
	(c, s, f) = map(int, input().split())
	for j in range(i + 1):
		cur[j] = max(s, ceil(cur[j] / f) * f) + c
print(*cur, sep='\n')


n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for (i, (c, s, f)) in enumerate(csf):
	t = s + c
	for j in range(i + 1, n - 1):
		(C, S, F) = (csf[j][0], csf[j][1], csf[j][2])
		t = max(t, S)
		t = -(-t // F) * F + C
	print(t)
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())
ans = [0] * N

def nex(a, ls):
	x = -a % ls[2]
	return max([ls[1], a + x]) + ls[0]
M = N - 1
for i in range(M):
	station = [int(s) for s in input().split()]
	for j in range(i + 1):
		ans[j] = nex(ans[j], station)
for e in ans:
	print(e)


N = int(input())
C = [None]
S = [None]
F = [None]
for i in range(1, N):
	(Ci, Si, Fi) = map(int, input().split())
	C.append(Ci)
	S.append(Si)
	F.append(Fi)
for i in range(1, N):
	t = S[i]
	for j in range(i, N - 1):
		t = max((t + C[j] + F[j + 1] - 1) // F[j + 1] * F[j + 1], S[j + 1])
	t = t + C[N - 1]
	print(t)
print(0)


N = int(input())
CSFlist = [tuple(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
	now = 0
	for (c, s, f) in CSFlist[i:]:
		now = max(now, s)
		now += f - now % f if now % f != 0 else 0
		now += c
	print(now)


N = int(input())
(C, S, F) = ([], [], [])
for i in range(N - 1):
	(c, s, f) = map(int, input().split())
	C += [c]
	S += [s]
	F += [f]
for i in range(N - 1):
	t = 0
	for j in range(i, N - 1):
		if t <= S[j]:
			t = S[j]
		else:
			t = F[j] * (t // F[j] + (t % F[j] != 0))
		t += C[j]
	print(t)
print(0)


N = int(input())
T = [tuple(map(int, input().split())) for _ in range(N - 1)]
ans = [0] * N
for i in range(N - 1):
	for j in range(i, N - 1):
		(C, S, F) = T[j]
		now = ans[i] if S <= ans[i] else S
		ans[i] = now + (F - now % F) % F + C
print(*ans, sep='\n')


N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for start in range(N):
	t = 0
	for i in range(start, N - 1):
		(C, S, F) = CSF[i]
		if t < S:
			t = S
		else:
			t += (F - (t - S) % F) % F
		t += C
	print(t)


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


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())
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)


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())
p = [list(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
	c = 0
	d = p[i:]
	for j in range(n - i - 1):
		if c < d[j][1]:
			c += d[j][1] + d[j][0] - c
		else:
			c += ((c - 1) // d[j][2] + 1) * d[j][2] + d[j][0] - c
	else:
		print(c)


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


n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for (i, [ci, si, fi]) in enumerate(csf):
	time = si + ci
	for (cj, sj, fj) in csf[i + 1:]:
		time = max(sj, time)
		time += (fj - time % fj) % fj + cj
	print(time)
print(0)


import sys
input = sys.stdin.readline
n = int(input())
tl = [0] * n
for i in range(n - 1):
	(c, s, f) = map(int, input().split())
	for j in range(i + 1):
		if tl[j] < s:
			tl[j] = s + c
		elif tl[j] % f == 0:
			tl[j] += c
		else:
			tl[j] += c + f - tl[j] % f
for k in tl:
	print(k)


n = int(input())
train = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
	cost = 0
	for j in range(i, n - 1):
		(c, s, f) = train[j]
		if cost >= s:
			cost += (s - cost) % f + c
		else:
			cost = c + s
	print(cost)


N = int(input())
src = [tuple(map(int, input().split())) for i in range(N - 1)]
ans = []
for i in range(N - 1):
	t = 0
	for (c, s, f) in src[i:]:
		if t <= s:
			t = s + c
		else:
			t += -t % f + c
	ans.append(t)
ans.append(0)
print(*ans, sep='\n')


N = int(input())
csf = [tuple(map(int, input().split(' '))) for i in range(N - 1)]
for i in range(N - 1):
	now = 0
	for j in csf[i:]:
		(c, s, f) = [k for k in j]
		while now > s:
			s += f
		now = s + c
	print(now)
print(0)


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


(N, *L) = map(int, open(0).read().split())
ans = 0
inf = [0] * (N - 1)
for (i, (c, s, f)) in enumerate(zip(*[iter(L)] * 3)):
	inf[i] = (c, s, f)
for i in range(N - 1):
	ans = 0
	for j in range(i, N - 1):
		(c, s, f) = inf[j]
		m = ((ans - 1) // f + 1) * f
		ans = max(m, s)
		ans += c
	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
	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())
csf = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N - 1):
	time = 0
	for (c, s, f) in csf[i:]:
		if time <= s:
			time = s + c
		elif time % f == 0:
			time += c
		else:
			time += c + f - time % f
	print(time)
print(0)


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]