Given two positive integers and , you can perform the following two types of operations any number of times (including zero times):
Choose an integer which satisfies , and change into . It will cost you coins to perform this operation once. The integer you choose each time can be different.
Change into . It will cost you coins to perform this operation once. Note that is the largest integer which is less than or equal to .
Given a positive integer , calculate the minimum number of coins needed to change into a multiple of . Please note that is a multiple of any positive integer.
输入格式
There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:
The first line contains five integers , , , , (, ).
输出格式
For each test case output one line containing one integer, indicating the minimum number of coins needed to change into a multiple of . If this goal cannot be achieved, output instead.