408212: GYM103055 F Fair Distribution
Description
There are $$$n$$$ robots and $$$m$$$ energy bars in the Dream Kingdom. DreamGrid, the king, is trying to make a fair distribution of the energy bars. A fair distribution exists if and only if the number of the energy bars is a multiple of the number of robots.
The only tool DreamGrid has is a powerful laser gun. Every time he turns on the laser gun, he can do exactly one of the two things:
- Create a new energy bar.
- Destroy a robot.
To avoid the extinction of robots, it's forbidden to destroy all the $$$n$$$ robots. It takes one dollar to turn on the laser gun once. You are asked to find the minimum cost of making a fair distribution.
InputThere are multiple test cases. The first line of the input contains an integer $$$T$$$ ($$$1 \le T \le 1\,000$$$), indicating the number of test cases. For each test case:
The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^8$$$), indicating the initial number of robots and energy bars.
OutputFor each test case output one line containing an integer, indicating the minimum cost to get a fair distribution.
ExampleInput3 3 12 10 6 8 20Output
0 4 2Note
For the third sample, the best way is to destroy a robot and create an energy bar. After that, we have $$$7$$$ robots and $$$21$$$ energy bars, which leads to a fair distribution.