N = int(eval(input()))



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



for i in range(N):  # 出発駅

  time = 0

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

    if time < CSF[j][1]:  # 開通まで待つ

      time = CSF[j][1]

    else:

      for k in range(CSF[j][2]):

        if (time + k) % CSF[j][2] == 0:

          time = time + k

          break

    time += CSF[j][0]

  print(time)

N = int(eval(input()))



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



for i in range(N):  # 出発駅

  time = 0

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

    if time < CSF[j][1]:  # 開通まで待つ

      time = CSF[j][1]

    elif time % CSF[j][2] == 0:

      pass

    else:

      time += CSF[j][2]-time%CSF[j][2]

    time += CSF[j][0]

  print(time)

N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N - 1)]
for i in range(N):  # 出発駅
    time = 0
    for j in range(i, N - 1):
        if time < CSF[j][1]:  # 開通まで待つ
            time = CSF[j][1]
        else:
            for k in range(CSF[j][2]):
                if (time + k) % CSF[j][2] == 0:
                    time = time + k
                    break
        time += CSF[j][0]
    print(time)

N = int(eval(input()))
CSF = [list(map(int, input().strip().split())) for _ in range(N - 1)]
for i in range(N):  # 出発駅
    time = 0
    for j in range(i, N - 1):
        if time < CSF[j][1]:  # 開通まで待つ
            time = CSF[j][1]
        elif time % CSF[j][2] == 0:
            pass
        else:
            time += CSF[j][2] - time % CSF[j][2]
        time += CSF[j][0]
    print(time)

+        elif time % CSF[j][2] == 0: +            pass -            for k in range(CSF[j][2]): -                if (time + k) % CSF[j][2] == 0: -                    time = time + k -                    break +            time += CSF[j][2] - time % CSF[j][2]