#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 stations on the railroad, numbered through from west to east.
Tomorrow, the opening ceremony of the railroad will take place.
On this railroad, for each integer such that , there will be trains that run from Station to Station in seconds. No other trains will be operated.
The first train from Station to Station will depart Station seconds after the ceremony begins. Thereafter, there will be a train that departs Station every seconds.
Here, it is guaranteed that divides .
That is, for each Time satisfying and , there will be a train that departs Station seconds after the ceremony begins and arrives at Station seconds after the ceremony begins, where denotes modulo , and there will be no other trains.
For each , find the earliest possible time we can reach Station if we are at Station when the ceremony begins, ignoring the time needed to change trains.
Constraints
- All input values are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. Assuming that we are at Station when the ceremony begins, if the earliest possible time we can reach Station is seconds after the ceremony begins, the -th line should contain .
Sample Input 1
3
6 5 1
1 10 1
Sample Output 1
12
11
0
We will travel from Station as follows:
- seconds after the beginning: take the train to Station .
- seconds: arrive at Station .
- seconds: take the train to Station .
- seconds: arrive at Station .
We will travel from Station as follows:
- seconds: take the train to Station .
- seconds: arrive at Station .
Note that we should print for Station .
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