An archaeologist is deciphering an equation written in the runes of an ancient society. That society used base 10 and never wrote a number starting with 0. The professor has worked out most of the digit runes and a few of the operators, and he leaves the last one to you.
The professor hands you one simple equation. Every rune he knows is already rewritten as a digit, and the only operators he knows are addition +, subtraction -, and multiplication *, so no other operator appears. Each number is between −999999 and 999999, and consists of the digits 0 to 9, at most one leading -, and a few ?s. A ? marks one digit rune the professor cannot read, never an operator, never the =, never the leading -. All the ?s in one equation stand for the same digit from 0 to 9, and that digit differs from every digit already written in the equation.
A digit works if replacing every ? with it makes the equation true and leaves all three numbers written the way that society wrote numbers. A number of two or more characters cannot start with 0, and no number can start with -0. Zero is written as the single character 0.
If several digits work, find the smallest one. If none works, the professor has misread some of his runes, so report −1.
The first line holds the number of test cases T (1≤T≤100). Each of the next T lines holds one equation in the form [number][op][number]=[number].
Each number consists of the digits 0 to 9, with at most one leading -, and possibly some ?s. Ignoring the sign, a number is at most 6 characters long. No number starts with 0 except 0 itself, and no number starts with -0. The operator is one of +, -, *, and it sits between the first and the second number. The = is always between the second and the third number. There are no spaces, tabs, or other characters. Every equation holds at least one ?.
For each test case, print on its own line the smallest digit that can replace the ?s. If no digit works, print −1. Print no extra spaces and no blank lines.