n=int(eval(input()))

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



for i in range(n-1):

 ans=l[i][1]+l[i][0]

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

  if ans<l[j][1]:

   ans=l[j][1]+l[j][0]

  else:

   if ans%l[j][2]!=0:

    ans+=l[j][2]-(ans%l[j][2])

   ans+=l[j][0]

 print(ans)



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

n = int(eval(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))

-    ans = l[i][1] + l[i][0] +    t = l[i][1] +    t += l[i][0] -        if ans < l[j][1]: -            ans = l[j][1] + l[j][0] -        else: -            if ans % l[j][2] != 0: -                ans += l[j][2] - (ans % l[j][2]) -            ans += l[j][0] -    print(ans) +        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)