N,L = map(int,input().split()) et = 0 for i in range(N): x, w, t = map(int,input().split()) now = et + x if int(now / t) % 2 == 0: if t - now % t < w: et = et + (t-now % t) + t else: et = et + (t-now % t) print(et+L)