Musical Chairs

No attempts yetTime limit1sMemory limit128 MB

Problem

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

To recreate a similar game on a game console, the rules are changed as follows. N children are seated on N chairs arranged in a circle. The chairs are numbered from 1 to N. The program pre-selects a positive integer D. Starting from chair 1, the program counts children around the circle. When the count reaches D, that child leaves the game and their chair is removed. Counting then restarts from the next remaining chair. The last child remaining in the circle is the winner.

For example, consider N = 5 and D = 3. Counting starts at chair 1, so child #3 is the first to leave, and counting restarts with child #4. Child #1 is the second to leave, and counting restarts with child #2, which makes child #5 leave next. Child #2 is the last to leave, so child #4 is the winner.

Write a program that determines the winning child given N and D.

Input

The input contains one or more test cases. Each test case is a single line with two positive integers N and D, separated by one or more spaces, where N, D < 1,000,000.

The last line contains two zeros (0 0) and is not part of the test cases.

Output

For each test case, print a single line in the format:

N D W

where N and D are the given values, the fields are separated by single spaces, and W is the winner of that game.