Given a string of numbers with length and a target , try to insert the minimum number of +
s and *
s so that the result is . The expression will follow the usual priority order: *
take precedence over +
. Operands may have arbitrary number of leading zeros. For example, 09
is a valid operand.
Input Specification
The first line of the inputs consists of an integer denoting the number of test cases.
For each test case, the first line is a string of length consisting of numbers . The second line is an integer denoting the target.
Output Specification
For each test case, output a line with an integer denoting the minimum number of +
or *
that should be inserted to make the expression equal to the target . If there are no solutions, output -1.
Sample Input
3
032089
5
333
9
000000000000000
0
Sample Output
3
2
0
Explanation
In the first test case, the optimal one is . Recall that arbitrary number of leading zeros are allowed.
In the second test case, the optimal one is .
In the third test case, you don't have to insert any, so the answer is 0.
Constraints
For all test cases, , , .
Scoring
There are 20 test cases in total.
- For of test cases, .
- For of test cases, . (Note: this includes the first of test cases).
- For another of test cases, the output is either 1 or -1.
- For another of test cases, you only need to use
+
(if a solution exists). - For the rest of test cases, there are no additional constraints.
Comments