Chef wants to store some important numerical data on his personal computer. He is using a new data type that can store values only from till both inclusive. If this data type receives a value greater than then it is cyclically converted to fit into the range to . For example:
- Value will be stored as .
- Value will be stored as .
and so on…
Given , the value chef wants to store in this new data type. Determine what will be the actual value in memory after storing .
Input Format
- First line will contain , number of testcases. Then the testcases follow.
- Each testcase contains a single line of input, two space separated integers - the maximum value a data type can store and the value Chef wants to store in the data type respectively.
Output Format
For each testcase, output in a single line the value which will be actually stored in memory.
Constraints
Sample Input 1
5
15 0
15 10
11 12
27 37
50 49
Sample Output 1
0
10
0
9
49
Explanation
Test Case : The data type can store values from to . If we try to put in this data type, then the stored value will be the same, that is .
Test Case : The data type can store values from to . If we try to put in this data type, then the stored value will be the same, that is .
Test Case : The data type can store values from to . If we try to put in this data type, then the stored value will cyclically come back to . Hence the output is .
Test Case : The data type can store values from to . If we try to put in this data type, then the stored value will cyclically convert to . Hence the output is .
Solution:
No comments:
Post a Comment