


A person can also kill himself.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of each test case contains two integers ‘N’ and ‘K’. Where ‘N’ is the total no of persons standing around circle and ‘K’ number indicates kth person is killed.
For each test case, return a single integer denoting the position of the last person surviving.
You are not required to print the output explicitly, it has already been taken care of. Just implement the function.
1 <= ’T’ <= 50
1 <= ’N’,’K’ <= 10^4
Time Limit: 1 sec
Approach:- The key id is to store all positions of a person in vector and remove all kth position from starting point in vector. After removing an element from the vector starting point is also changed.
Algorithm:
The key idea is find the answer for ‘N’ persons around the circle first find the answer for 'N-1' persons. First kill the Kth person from 1st position then recursively call on 'N-1'. It will give the position but according to with Kth person index set as 1. So to set the index will add ‘K’ to the index and will do mod ‘N’. If it comes out to be 0 then the value of index is ‘N’.