Given two positive integers $$$n$$$ and $$$k$$$, you can perform the following two types of operations any number of times (including zero times):
Given a positive integer $$$m$$$, calculate the minimum number of coins needed to change $$$n$$$ into a multiple of $$$m$$$. Please note that $$$0$$$ is a multiple of any positive integer.
There are multiple test cases. The first line of the input contains an integer $$$T$$$ ($$$1\leq T\leq 10^5$$$) indicating the number of test cases. For each test case:
The first line contains five integers $$$n$$$, $$$k$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1\leq n\leq 10^{18}$$$, $$$1\leq k, m, a, b\leq 10^9$$$).
For each test case output one line containing one integer, indicating the minimum number of coins needed to change $$$n$$$ into a multiple of $$$m$$$. If this goal cannot be achieved, output $$$-1$$$ instead.
4101 4 207 3 58 3 16 100 1114 514 19 19 8101 1 3 1 1
11 2 0 -1
For the first sample test case, initially $$$n=101$$$. The optimal steps are shown as follows:
For the second sample test case, perform the second type of operation twice will change $$$n$$$ into $$$0$$$. The total cost is $$$1 + 1 = 2$$$ coins.
For the third sample test case, as $$$n = 114 = 6 \times 19$$$ is already a multiple of $$$m$$$, no operation is needed. The total cost is $$$0$$$ coins.
| Название |
|---|


