Bob's Operator Puzzle
Alice writes a string of n decimal digits on a chalkboard and picks a target value T.
She hands the chalk to Bob, who may fill each of the n-1 gaps between consecutive digits
with one of the symbols +, -, *, or nothing at all (which simply glues the two digits
together into one longer number). The result is an arithmetic expression using the digits
in their original order.
Two rules apply. First, no number formed this way may have a leading zero — the number 0
by itself is fine, but 05 or 00 is not. Second, the expression is evaluated with the
usual rules of arithmetic: * binds tighter than + and -, and every + or - is a
binary operator sitting between two numbers (there is no unary minus).
Alice wants to know how many of Bob's expressions evaluate to exactly T. Since there can
be a lot of them, she only asks to see the lexicographically smallest 100 — comparing the
resulting expressions as plain strings, character by character, using their usual character
codes (so * < + < - < any digit).
Input
The first line contains an integer q (1 ≤ q ≤ 200) — the number of test cases.
Each of the next q lines contains a digit string s and an integer T, separated by a
single space: 1 ≤ |s| ≤ 10, every character of s is a digit 0-9, and
-10^12 ≤ T ≤ 10^12.
Output
For each test case, in the order given, print a line with a single integer — the number of
ways Bob can fill the gaps so the resulting expression equals T. Then print the
lexicographically smallest min(count, 100) such expressions, one per line, in increasing
order. If the count is 0, print no expression lines for that case.
Notes
In the first example, s = "123" and T = 6. Two of the sixteen possible expressions equal
6: 1*2*3 and 1+2+3. Comparing them as strings, 1*2*3 comes first because * (character
code 42) is smaller than + (character code 43) at the second position.
For s = "105" and T = 5, the fillings 1+05, 1-05 and 1*05 are all illegal because
05 has a leading zero. The only two legal fillings that equal 5 are 1*0+5 and 10-5.