Crazy Calculator 

The two properties of arithmetic operators which determine the order in which they are executed in an expression are their precedence levels and their associativities. Precedence levels determine the order in which operators with different precedence levels are executed. Associativities determine the order in which a repeated operator is executed. Left associative operators are evaluated left to right while right associative operators are evaluated right to left. Different operators with equal precedence levels are evaluated left to right. Examples:

In the Southeastern region of the planet ACM, a strange collection of dialects has resulted in the use of non-standard operators for the integer operations of plus, minus, times, and integer divide. The operations are the usual binary operations, but the symbols used, their precedences and their associativities, vary widely across the region. Your team is to write a program that will implement a simple integer calculator with operations "+", "-", "*", and "/" where "/" denotes integer division. The catch is, your calculator has to deal with all of the local dialects.


The input file will contain 4 lines that describe the local symbol set followed by 1 or more lines each containing an expression using the local symbol set to be evaluated. The first four lines each contain a four character string tex2html_wrap_inline45 beginning in column one, where:

tex2html_wrap_inline47 denotes the standard operator that is being described

tex2html_wrap_inline49 denotes the local symbol being used for that operator

tex2html_wrap_inline51 is a digit denoting the local precedence of the operator (higher digit means higher precedence)

tex2html_wrap_inline53 is a single letter denoting the local associativity of the opearator (L for left associativity, R for right).

The line


means that the symbol @ will be used to denote minus which will be right associative and have precedence 1. The expression 5@3@1 under these circumstances will evaluate to 3.


For each input expression, your program must print one line containing the expression with standard operators followed by a space, an equal sign, and the result.

Sample input

2@3~1 2/6/5+3

Sample output

1 +1 = 2
5+5-4 = 6
2+3*12/6/5-3= 14


The last expression, parenthesized to show you the order of execution is (2+((3*12)/(6/(5-3)))).