You are given an N−sided polygon where vertices are numbered from 1 to N in clockwise order, You are also given an integer K. You create a vertex-explosion machine that explodes vertex in polygon thereby reducing the size of the polygon. You start with vertex 2. At each step, one of the following operations on the polygon is performed:
Note: Polygon with vertex 2 and 1 exists
For example, if N=4 and K=2, then the following diagram displays an explanation.
You are required to determine the remaining last vertex.
Input format
Output format
Print an integer denoting the last-remaining vertex.
Constraints
1≤T≤10
3≤N≤1014
1≤K≤1014
Explanation of Test Case 1: In the given figure
Explanation of Test Case 2:
Explanation of Test Case 4: