#arc150b. [arc150_b]Make Divisible

[arc150_b]Make Divisible

Problem Statement

You are given positive integers AA and BB.

Find the minimum value of X+YX+Y for non-negative integers XX and YY such that B+YB+Y is a multiple of A+XA+X.

You have TT test cases to solve.

Constraints

  • 1leqTleq1001 \\leq T \\leq 100
  • 1leqA,Bleq1091 \\leq A,\\ B \\leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

TT mathrmcase1\\mathrm{case}_{1} mathrmcase2\\mathrm{case}_{2} vdots\\vdots mathrmcaseT\\mathrm{case}_{T}

Each case is in the following format:

AA BB

Output

Print TT lines. The ii-th line should contain the answer for the ii-th test case.


Sample Input 1

5
11 23
8 16
4394 993298361
95392025 569922442
8399283 10293

Sample Output 1

2
0
65
2429708
8388990

For the first test case, if we let X=1X=1 and Y=1Y=1, then B+Y=24B+Y=24 will be a multiple of A+X=12A+X=12. Here, we have X+Y=2X+Y=2, and there is no way to make X+YX+Y smaller, so the answer is 22.

For the second test case, if we let X=0X=0 and Y=0Y=0, then B+Y=16B+Y=16 will be a multiple of A+X=8A+X=8.