Students numbered to sit in a circle and play a counting-out game. The counting starts from student and goes around the circle; every -th student is out of the game, and the counting continues from the next one. Your task is to determine which student remains last.
Input
First line of input will be a single integer - the number of testcases.
Each of the next lines contains two integers and - the number of students and the length of the count.
Output
For every testcase print a single line with the number of the last remaining student.
Example
2 8 3 2 2
6 0
In the first testcase the students leave in the order and student remains. In the second, counting eliminates student , so student remains.
Constraints
This problem was adapted, with permission, from Josifov problem, authored by Društvo matematičara Srbije and Fondacija Petlja.