Gats and the Resonant Jump
Gats is standing beside a circular track containing stones labeled .
If Gats starts on stone , one jump of length takes him to stone
The tuning value of a stone labeled is . In particular, the tuning value of stone is .
A starting stone is called resonant if its tuning value is unchanged by the jump, meaning
For each test case, determine how many of the possible starting stones are resonant.
Input
The first line contains an integer (), the number of test cases.
Each of the next lines contains two integers and (, ), the number of stones and the jump length.
Output
For each test case, print one integer: the number of resonant starting stones.
Samples
Sample 1
Input
5 5 1 6 2 8 2 9 3 12 12
Output
3 2 4 7 12
For , the resonant starting stones are . For , they are . For , they are . For , every stone except and is resonant. In the final test case, the jump returns Gats to the starting stone, so every stone is resonant.