N = int(eval(input()))

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



for i in range(N-1):

    t = train[i][0] + train[i][1]

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

        if train[j][1] >= t:

            t = train[j][1] + train[j][0]

        elif t % train[j][2] == 0:

            t += train[j][0]

        else:

            #print(t+train[j][2]-t%train[j][2])

            t = t+train[j][2]-t%train[j][2]

            t += train[j][0]

    print(t)

print((0))

N = int(eval(input()))

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



for i in range(N-1):

    t = csf[i][1]

    t += csf[i][0]

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

        st = csf[j][1]

        f = csf[j][2]

        t = max(st, ((t-1)//f+1)*f)

        t += csf[j][0]



    print(t)

print((0))





N = int(eval(input()))
train = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N - 1):
    t = train[i][0] + train[i][1]
    for j in range(i + 1, N - 1):
        if train[j][1] >= t:
            t = train[j][1] + train[j][0]
        elif t % train[j][2] == 0:
            t += train[j][0]
        else:
            # print(t+train[j][2]-t%train[j][2])
            t = t + train[j][2] - t % train[j][2]
            t += train[j][0]
    print(t)
print((0))

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

-train = [list(map(int, input().split())) for _ in range(N - 1)] +csf = [list(map(int, input().split())) for _ in range(N - 1)] -    t = train[i][0] + train[i][1] +    t = csf[i][1] +    t += csf[i][0] -        if train[j][1] >= t: -            t = train[j][1] + train[j][0] -        elif t % train[j][2] == 0: -            t += train[j][0] -        else: -            # print(t+train[j][2]-t%train[j][2]) -            t = t + train[j][2] - t % train[j][2] -            t += train[j][0] +        st = csf[j][1] +        f = csf[j][2] +        t = max(st, ((t - 1) // f + 1) * f) +        t += csf[j][0]