Candy Distribution

Time limit1sMemory limit128 MB

Problem

At a party with $K$ guests, the candy must be shared fairly, so the number of candies must be a multiple of $K$ - exactly $K \times X$ candies for some positive integer $X$. Because at least one guest always loses a candy, one extra candy is bought, making the total $K \times X + 1$ candies.

Candy is sold only in bags, and every bag contains exactly $C$ candies, so buying $B$ bags yields $B \times C$ candies. A purchase of $B$ bags is valid when $B \times C = K \times X + 1$ holds for some positive integer $X$; in particular the total number of candies is at least $K + 1$.

Input

The first line contains the number of test cases $t$ ($0 < t < 100$). Each of the next $t$ lines contains two integers $K$ and $C$ separated by a space ($1 \le K, C \le 10^9$). The buyer can never purchase more than $10^9$ bags, so only $1 \le B \le 10^9$ is allowed.

Output

For each test case, print the minimum number of bags $B$ that makes the purchase valid. If no valid number of bags exists within the allowed range, print IMPOSSIBLE instead. Print one answer per line.