Firefighters
A damaged arithmetic expression retains its positive integer constants, parentheses, and known operators, but each lost operator is written as ?. Determine whether replacing every ? independently by +, -, *, or / can make the expression equal a required result.
Use ordinary precedence: multiplication and division before addition and subtraction; operators of equal precedence are left-associative. Integer division discards the fractional part. Expressions contain at most 100 symbols, each parenthesized expression encloses at most one operator and its two operands (which may themselves be parenthesized expressions), constants are between 1 and 999, and there are at most 10 question marks.
Input
The first line contains N. Each equation then occupies two lines: the expression, with no spaces, and its integer target. Every expression is syntactically valid.
Output
For each equation, print yes if some replacement reaches the target; otherwise print no.
Example
Input:
3
1?((2*(3*4))+(5+6))
35
1?2*3+4-14
0
1?3*4/5*6+12
11
Output:
yes
no
no
Submit solution
Sign in to submit a solution.