N = int(eval(input()))

lines = []



for i in range(N-1):

    lines.append(eval(input()))



C = []

S = []

F = []



for line in lines:

	c, s, f = line.split()

	C.append(int(c))

	S.append(int(s))

	F.append(int(f))



A = []



for i in range(N-1):

	a = C[i] + S[i]

	for j in range(i + 1, N - 1):

		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]

		n = F[j] - n if a > S[j] and n != 0 else n

		# n = S[j] - a if a <= S[j] else a % F[j]

		a = a + C[j] + n

	A.append(a)



for a in A:

	print(a)

print((0))



N = int(eval(input()))

lines = []



for i in range(N-1):

    lines.append(eval(input()))



C = []

S = []

F = []



for line in lines:

	c, s, f = line.split()

	C.append(int(c))

	S.append(int(s))

	F.append(int(f))



A = []



for i in range(N-1):

	a = C[i] + S[i]

	for j in range(i + 1, N - 1):

		if a <= S[j]:

			n = S[j] - a

		else:

			mod = a % F[j] 

			n = F[j] - mod if mod != 0 else 0

		a = a + C[j] + n

	A.append(a)



for a in A:

	print(a)

print((0))



N = int(eval(input()))
lines = []
for i in range(N - 1):
    lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
    c, s, f = line.split()
    C.append(int(c))
    S.append(int(s))
    F.append(int(f))
A = []
for i in range(N - 1):
    a = C[i] + S[i]
    for j in range(i + 1, N - 1):
        n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
        n = F[j] - n if a > S[j] and n != 0 else n
        # n = S[j] - a if a <= S[j] else a % F[j]
        a = a + C[j] + n
    A.append(a)
for a in A:
    print(a)
print((0))

N = int(eval(input()))
lines = []
for i in range(N - 1):
    lines.append(eval(input()))
C = []
S = []
F = []
for line in lines:
    c, s, f = line.split()
    C.append(int(c))
    S.append(int(s))
    F.append(int(f))
A = []
for i in range(N - 1):
    a = C[i] + S[i]
    for j in range(i + 1, N - 1):
        if a <= S[j]:
            n = S[j] - a
        else:
            mod = a % F[j]
            n = F[j] - mod if mod != 0 else 0
        a = a + C[j] + n
    A.append(a)
for a in A:
    print(a)
print((0))

-        n = S[j] - a if a <= S[j] else (a - S[j]) % F[j] -        n = F[j] - n if a > S[j] and n != 0 else n -        # n = S[j] - a if a <= S[j] else a % F[j] +        if a <= S[j]: +            n = S[j] - a +        else: +            mod = a % F[j] +            n = F[j] - mod if mod != 0 else 0