N = int(eval(input()))

CSF = [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 < CSF[j][1]:

            T = CSF[j][1]

        else:

            if T % CSF[j][2] != 0:

                T += (CSF[j][2] - T % CSF[j][2])

        T += CSF[j][0]

    print(T)



N = int(eval(input()))

C, S, F = [], [], []

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

    T = 0

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

        if S[j] > T:

            T = S[j]



        if T % F[j] != 0:

            T += F[j] - T%F[j]



        T += C[j]



    print(T)

N = int(eval(input()))
CSF = [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 < CSF[j][1]:
            T = CSF[j][1]
        else:
            if T % CSF[j][2] != 0:
                T += CSF[j][2] - T % CSF[j][2]
        T += CSF[j][0]
    print(T)

N = int(eval(input()))
C, S, F = [], [], []
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(N):
    T = 0
    for j in range(i, N - 1):
        if S[j] > T:
            T = S[j]
        if T % F[j] != 0:
            T += F[j] - T % F[j]
        T += C[j]
    print(T)

-CSF = [list(map(int, input().split())) for i in range(N - 1)] -# 鉄道種類ループ +C, S, F = [], [], [] +for i in range(N - 1): +    ci, si, fi = list(map(int, input().split())) +    C.append(ci) +    S.append(si) +    F.append(fi) -    # 鉄道乗り継ぎループ -        if T < CSF[j][1]: -            T = CSF[j][1] -        else: -            if T % CSF[j][2] != 0: -                T += CSF[j][2] - T % CSF[j][2] -        T += CSF[j][0] +        if S[j] > T: +            T = S[j] +        if T % F[j] != 0: +            T += F[j] - T % F[j] +        T += C[j]