Make It Round
Contest: Codeforces Round  834 (Div. 3)
Difficulty rating: 1400
Tags: brute force, number theory

Inflation has occurred in Berlandia, so the store needs to change the price of goods.

The current price of good $$$n$$$ is given. It is allowed to increase the price of the good by $$$k$$$ times, with $$$1 \le k \le m$$$, k is an integer. Output the roundest possible new price of the good. That is, the one that has the maximum number of zeros at the end.

For example, the number 481000 is more round than the number 1000010 (three zeros at the end of 481000 and only one at the end of 1000010).

If there are several possible variants, output the one in which the new price is maximal.

If it is impossible to get a rounder price, output $$$n \cdot m$$$ (that is, the maximum possible price).

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test.

Each test case consists of one line.

This line contains two integers: $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$). Where $$$n$$$ is the old price of the good, and the number $$$m$$$ means that you can increase the price $$$n$$$ no more than $$$m$$$ times.

Output format:
For each test case, output on a separate line the roundest integer of the form $$$n \cdot k$$$ ($$$1 \le k \le m$$$, $$$k$$$ — an integer).

If there are several possible variants, output the one in which the new price (value $$$n \cdot k$$$) is maximal.

If it is impossible to get a more rounded price, output $$$n \cdot m$$$ (that is, the maximum possible price).

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first case $$$n = 6$$$, $$$m = 11$$$. We cannot get a number with two zeros or more at the end, because we need to increase the price $$$50$$$ times, but $$$50 > m = 11$$$. The maximum price multiple of $$$10$$$ would be $$$6 \cdot 10 = 60$$$.

In the second case $$$n = 5$$$, $$$m = 43$$$. The maximum price multiple of $$$100$$$ would be $$$5 \cdot 40 = 200$$$.

In the third case, $$$n = 13$$$, $$$m = 5$$$. All possible new prices will not end in $$$0$$$, then you should output $$$n \cdot m = 65$$$.

In the fourth case, you should increase the price $$$15$$$ times.

In the fifth case, increase the price $$$12000$$$ times.

Example input:
10
6 11
5 43
13 5
4 16
10050 12345
2 6
4 30
25 10
2 81
1 7

Example output:
60
200
65
60
120600000
10
100
200
100
7

Editorial:
The answer is $$$n \cdot k$$$.
First, count two numbers: $$$cnt_2, cnt_5$$$ which denote the degree of occurrence of $$$2$$$ and $$$5$$$ in the number $$$n$$$ respectively, that is $$$n = 2^cnt_2 \cdot 5^cnt_5 \cdot d$$$. Where $$$d$$$ is not divisible by either $$$2$$$ or $$$5$$$. Now while $$$cnt_2 \neq cnt_5$$$ we will increase the corresponding value. For example, if $$$cnt_2 < cnt_5$$$, then as long as $$$cnt_2 \neq cnt_5$$$ and at that $$$k \cdot 2 \le m$$$ we will increase $$$cnt_2$$$ by $$$1$$$ and multiply $$$k$$$ by $$$2$$$ times.
That way we can get the most round number possible by spending the least possible $$$k$$$.
Now we either have $$$cnt_2 = cnt_5$$$, or $$$k \cdot 5 > m$$$ or $$$k \cdot 2 > m$$$. Then in the first case, we will multiply the number $$$k$$$ by $$$10$$$ as long as we can. That is, until $$$k \cdot 10 \le m$$$.
Now in either case we have: $$$k \cdot 10 > m$$$. Then $$$\lfloor \frac{m}{k} \rfloor = x < 10$$$. Then we multiply $$$k$$$ by $$$x$$$ times and get our desired answer.
In the last step, we can no longer get a rounder number, but just find the maximal possible number.