创建于 2026/07/16 · 更新于 2026/07/16
Frog Q has a secret integer . Frog Q's friend F only knows that .
To reveal to F, Q may perform several hint operations. In each operation:
After some number of hints, if F can uniquely determine the value of , the communication succeeds.
Q wants to minimize the total cost. Compute this minimum total cost.
The first line contains an integer , the number of test cases.
The next lines each contain two integers , separated by a space.
Output lines, each containing a single integer — the minimum total cost for the corresponding test case.
If F can never uniquely determine the value of , output .
5
5 3
8 3
10 3
2147483647 10
144322 17
0
1
-1
-1
10