Bill teaches chemistry at school and has prepared a number of tests for his students. Each test contains a chemical formula and several possible reaction outcomes. The students should choose the correct one. Bill wants to ensure that when entering these tests into the computer, he did not make any mistakes, and that students cannot simply exclude incorrect answers by counting the number of chemical elements on the left and right sides of the equation. In a correct chemical reaction, the number of atoms for each element on both sides must always be equal.
Your task is to help Bill by writing a program to check each proposed right-hand side of the equation. The program must compare the total number of each chemical element on the given left side to the corresponding total on each of the proposed right sides.
Each side of the equation is given as a string of characters (no spaces). A side consists of one or more chemical sequences separated by a '+' character. Each sequence may optionally begin with an integer multiplier that applies to the whole sequence and contains a series of elements. Each element may also be followed by an integer multiplier. An element can be either a distinct chemical element, or a group enclosed in parentheses. Each distinct chemical element is represented by either a single capital letter, or by a capital letter followed by a lowercase letter.
Formally, in a BNF-like notation:
<formula> ::= [<number>]<sequence>{'+'[<number>]<sequence>}
<sequence> ::= <element>[<number>]{<element>[<number>]}
<element> ::= <atom> | '(' <sequence> ')'
<atom> ::= <uppercase>[<lowercase>]
<uppercase> ::= 'A'..'Z'
<lowercase> ::= 'a'..'z'
<number> ::= '1'..'9'{'0'..'9'}
A chemical element is counted as occurring times in the formula, where is the sum of all instances multiplied by the appropriate multipliers. For example, in the formula
C2H5OH+3O2+3(SiO2)
we have:
C occurs times,
H occurs times (5+1),
O occurs times (1+3\times2+3\times2),
Si occurs times.
All explicit multipliers in the formula are positive integers of at least , and are by default. Each formula is at most characters long, and no element occurs more than times in any formula.
The first line contains the formula for the left side of the equation. The second line contains the integer (1 \leq N \leq 10), the number of right-side candidates. Each of the following lines contains a proposed formula for the right side.
Print lines, one for each right-hand side. For each, output:
<left_formula>==<right_formula>
if the totals for every element are equal on both sides, otherwise output:
<left_formula>!=<right_formula>
Here, <left_formula> and <right_formula> are replaced by the exact formulas from the input (character for character). Do not include spaces in the output lines.
Example 1