Calling All Programmers#6644

Calling All Programmers

1 second
128 megabytes
Easy

A local radio station is holding a phone-in contest, and deejay J-Z Phus is in charge of administering the contest. He goes on the air at random times and announces things like "The fifth caller will get a chance for the grand prize". At this point, the switchboard lights up with dozens of callers. All these callers show up on a monitor in front of J-Z numbered , , etc. J-Z could just pick caller number at this point, but since he figures that everyone basically called in at the same time, he has decided on a different method. He picks a random number - say - and then starts eliminating every seventh caller. If he hits the end of the switchboard while counting, he cycles back to the beginning, but once a caller is eliminated, their position is no longer used in the count. After eliminating callers, he moves down more positions and obtains his "fifth" caller. The figure below show how this would work if J-Z's switchboard held callers. In this case, the caller in position is selected as the "fifth" caller.

prb6644.gif

Of course, the choice of "fifth" caller, the number of callers, and the use of the number can change from call-in to call-in. You are to write a general program to determine which caller is selected given all of the pertinent information.

Input

Each test consists of a single line containing three positive integers , where is the number of callers on the switchboard, and is the number of positions J-Z skips over each time until he gets to the -th caller. The value of n \geq k. In the above example, n = 10, m = 7 and k = 5. The maximum value for any of these values is . A line containing three zeros will terminate input.

Output

For each test case, output the position of the caller chosen as the -th caller.

Examples

Example 1

Loading
Loading