'THE MORNING COMMUTE'

from sys import stdin

from math import ceil

for i in range(int(input())):

    n=int(stdin.readline())
    xi,li,fi=map(int,stdin.readline().split())
    t=xi-0+li
    xa=xi+li
    for j in range(n-1):
        xi,li,fi=map(int,stdin.readline().split())
        if xa<xi:
            t+=xi-xa+li
        elif xa==xi:
            t+=li
        else:
            k=ceil((xa-xi)/fi)
            t+=xi+k*fi-xa+li
            xa=xi+k*fi+li
    print(t)

THIS IS MY CODE IN PYTHON 3.1.2

I GOT THE RIGHT RESULTS WITH THE TEST CASES BUT CODECHEF GIVES WRONG ANSWER…PLEASE HELP!!!