352. Josephus problem
Given the total number of people n and a number k which indicates that k-1 people are skipped and the kth person is killed in a circle in a fixed direction. The task is to determine the safest position in the circle so that when you perform these operations starting from the 1st position in the circle, you are the last one remaining and survive.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains 2 integers n and k.
For each test case, output the safest position that satisfies the above condition in a new line.
2 3 2 5 3
1 <= T <= 100 1 <= k, n <= 20