#abc084c. [abc084_c]Special Trains

[abc084_c]Special Trains

Problem Statement

A railroad running from west to east in Atcoder Kingdom is now complete.

There are NN stations on the railroad, numbered 11 through NN from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer ii such that 1iN11≤i≤N-1, there will be trains that run from Station ii to Station i+1i+1 in CiC_i seconds. No other trains will be operated.

The first train from Station ii to Station i+1i+1 will depart Station ii SiS_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station ii every FiF_i seconds.

Here, it is guaranteed that FiF_i divides SiS_i.

That is, for each Time tt satisfying SitS_i≤t and tFi=0t%F_i=0, there will be a train that departs Station ii tt seconds after the ceremony begins and arrives at Station i+1i+1 t+Cit+C_i seconds after the ceremony begins, where ABA%B denotes AA modulo BB, and there will be no other trains.

For each ii, find the earliest possible time we can reach Station NN if we are at Station ii when the ceremony begins, ignoring the time needed to change trains.

Constraints

  • 1N5001≤N≤500
  • 1Ci1001≤C_i≤100
  • 1Si1051≤S_i≤10^5
  • 1Fi101≤F_i≤10
  • SiFi=0S_i%F_i=0
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN C1C_1 S1S_1 F1F_1 :: CN1C_{N-1} SN1S_{N-1} FN1F_{N-1}

Output

Print NN lines. Assuming that we are at Station ii (1iN)(1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station NN is xx seconds after the ceremony begins, the ii-th line should contain xx.


Sample Input 1

3
6 5 1
1 10 1

Sample Output 1

12
11
0

We will travel from Station 11 as follows:

  • 55 seconds after the beginning: take the train to Station 22.
  • 1111 seconds: arrive at Station 22.
  • 1111 seconds: take the train to Station 33.
  • 1212 seconds: arrive at Station 33.

We will travel from Station 22 as follows:

  • 1010 seconds: take the train to Station 33.
  • 1111 seconds: arrive at Station 33.

Note that we should print 00 for Station 33.


Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0