Problem
You are given two integers
and . You may perform the following operation any number of times (including zero): change to , i.e. subtract from . Find the smallest non-negative integer value of you can obtain this way.
Here is the Problem link : Smallest Possible Whole Number CodeChef
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains two space-separated integers and .
Output
For each test case, print a single line containing one integer — the smallest value you can get.
Constraints
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
Input
Output
3
5 2
4 4
2 5
1
0
2
Explanation:
Example case 1:
- First, we change to .
- Then, we have and we change it to .
Since , the process stops here and the smallest value is .
Example case 2: We change to . Since , the process stops here and the smallest value is .
Example case 3: Since initially, we should not perform any operations and the smallest value is .
ANSWER