- Time limit: 1.00 s
- Memory limit: 512 MB
Consider a game where there are children (numbered ) in a circle. During the game, every second child is removed from the circle, until there are no children left.
Your task is to process queries of the form: "when there are children, who is the th child that will be removed?"
Input
The first input line has an integer : the number of queries.
After this, there are lines that describe the queries. Each line has two integers and : the number of children and the position of the child.
Output
Print integers: the answer for each query.
Constraints
Example
Input:
4 7 1 7 3 2 2 1337 1313
Output:
2 6 1 1107