Character Decoding 

This is a test for decoding characters' values. Assume a numerical expression is encoded in English characters by replacing some digit numbers (from 0 to 9) with English characters. So this kind of numerical expressions can be expressed in new forms, such as

2BAD = ABE + CD

Please write a program to decode the expressions in characters and output the numerical value of characters, according to the following rules and assumptions.

1.
All character values are integers between 0 to 9 both inclusive.

2.
An expression is represented as a set of items combined with operators. Only the operators +, - and = are used in each expression. And at most 5 items are used in one expression.

3.
There is one and only one operator = in each expression. And only one item is in the left-hand side of the operator =.

4.
Each item is represented by a combination of capital English characters and digital numbers. The value of the left-most character in each item is not 0.

5.
The input data are represented as several rows of numerical expressions and are stored in a file. Each row is an independent expression with other rows. The end of the input file is a star symbol (*).

6.
Output the value of the left-most item in each expression row by row, in the same order as that in the input file.

7.
If there are multiple solutions, print out the smallest values for each left-most item. If no possible solutions exist, print out a question mark (?) instead.

Input 

Contains k lines, with k-1 expressions.

Line 1 		 the first expression 
... 
Line k-1 the 

(k-1)th 
Line k A star symbol indicating end-of-file

Output 

Contains k - 1 lines. Each line is the smallest value that satisfies the corresponding expression.

Line 1 		 value 
... 
Line k-1 value

Sample Input 

CA = AB + 6C
DDE5 = DEFG - EHI + DDH
A = 0
*

Sample Output 

81
1115
?



Miguel Revilla
2000-08-14