Let us define sequences similar to those of Collatz with two parameters and . Given a number , the algorithm to get the next number is:
if is even, we move to ;
otherwise, we move to .
The standard Collatz sequence corresponds to and .
Given , and a starting number , compute the length of the cycle reached by applying the above algorithm. For example, if , and , then the defined sequence is 8, 5, 20, 11, 38, 20, 11, 38, … so the cycle has length 3.
Since numbers can become very large, and we have no mathematical guarantee that we will reach a cycle, we will stop if at some point the sequence reaches a number greater than .
Input consists of several cases, each with three natural numbers , and . Assume that both and do not exceed 1000, that is odd (for the sequence to have some interest), and that the initial is not larger than .
For every case, print the length of the cycle, or the first number that strictly exceeds .
Input
1 5 8 0 5 0 10 11 3 7 3 6 1 999 1000000 433 805 215476 0 1 333333
Output
3 1 1 35 1501002 490 3