N = int(eval(input()))

Nminus1 = N - 1

# lines = []



C = [0 for _ in range(Nminus1)]

S = [0 for _ in range(Nminus1)]

F = [0 for _ in range(Nminus1)]



for i in range(Nminus1):

    c, s, f = input().split()



    C[i] = int(c)

    S[i] = int(s)

    F[i] = int(f)



# for line in lines:

#     c, s, f = line.split()

#     C.append(int(c))

#     S.append(int(s))

#     F.append(int(f))



for i in range(Nminus1):

    a = C[i] + S[i]

    for j in range(i + 1, Nminus1):

        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

    print(a)



print((0))

N = int(eval(input()))

Nminus1 = N - 1

# lines = []



CSF = [0 for _ in range(Nminus1)]

# S = [0 for _ in range(Nminus1)]

# F = [0 for _ in range(Nminus1)]



for i in range(Nminus1):

    c, s, f = input().split()

    CSF[i] = (int(c), int(s), int(f))

    # C[i] = int(c)

    # S[i] = int(s)

    # F[i] = int(f)



# for line in lines:

#     c, s, f = line.split()

#     C.append(int(c))

#     S.append(int(s))

#     F.append(int(f))



for i in range(Nminus1):

    a = 0

    for j in range(i, Nminus1):

        C, S, F = CSF[j]

        if a <= S:

            n = S - a

        else:

            mod = a % F 

            n = F - mod if mod != 0 else 0

        a = a + C + n

    print(a)



print((0))
N = int(eval(input()))
Nminus1 = N - 1
# lines = []
C = [0 for _ in range(Nminus1)]
S = [0 for _ in range(Nminus1)]
F = [0 for _ in range(Nminus1)]
for i in range(Nminus1):
    c, s, f = input().split()
    C[i] = int(c)
    S[i] = int(s)
    F[i] = int(f)
# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))
for i in range(Nminus1):
    a = C[i] + S[i]
    for j in range(i + 1, Nminus1):
        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
    print(a)
print((0))

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

-C = [0 for _ in range(Nminus1)] -S = [0 for _ in range(Nminus1)] -F = [0 for _ in range(Nminus1)] +CSF = [0 for _ in range(Nminus1)] +# S = [0 for _ in range(Nminus1)] +# F = [0 for _ in range(Nminus1)] -    C[i] = int(c) -    S[i] = int(s) -    F[i] = int(f) +    CSF[i] = (int(c), int(s), int(f)) +    # C[i] = int(c) +    # S[i] = int(s) +    # F[i] = int(f) -    a = C[i] + S[i] -    for j in range(i + 1, Nminus1): -        if a <= S[j]: -            n = S[j] - a +    a = 0 +    for j in range(i, Nminus1): +        C, S, F = CSF[j] +        if a <= S: +            n = S - a -            mod = a % F[j] -            n = F[j] - mod if mod != 0 else 0 -        a = a + C[j] + n +            mod = a % F +            n = F - mod if mod != 0 else 0 +        a = a + C + n