Musical Chairs#1337

Musical Chairs

1 second
64 megabytes
Very easy

In the traditional game of Musical Chairs, N+1 children run around chairs (placed in a circle) while music is playing. When the music stops, the children run to sit on available chairs. The child left standing leaves the game, one chair is removed, and the game continues with children. The last child to sit is the winner.

To adapt this game for modern gaming consoles, the rules are modified as follows: children are seated on chairs arranged in a circle. The chairs are numbered from to . Your program selects a positive number in advance. The counting starts from the first chair, and when the count reaches , that child leaves the game, and their chair is removed. Counting resumes with the next chair in the circle. The last remaining child is the winner.

For example, in the game shown in the figure above with N = 5 and D = 3, the dot marks the starting point for counting and indicates the child who leaves. First, child leaves, and counting restarts with child . Child is the second to leave, and counting resumes with child , resulting in child leaving. Child is the last to leave, and child is the winner. Given and , write a program to determine the winner.

Input

Your program will be tested on one or more test cases. Each test case consists of two positive integers and on a single line, separated by one or more spaces, where N, D < 1000000.

The last line of the input file contains two 's and is not part of the test cases.

Output

For each test case, output the winner in the following format:

N D W

where and are as above, a space character, and is the winner of that game.

Examples

Example 1

Loading
Loading