You and your friend Christian are taking a year off to travel around the world, see magnificent places, meet wonderful people and learn new cultures. Different cultures bring different units, and units are the differences that hurt an engineer the most. People measure in miles, firkins, microfortnights, candlepowers, pints and kilowatt hours when the SI base units in the table below would do the job.
| Quantity | Name | Symbol |
|---|---|---|
| length | metre | m |
| mass | kilogram | kg |
| time | second | s |
| electric current | ampere | A |
| temperature | kelvin | K |
| luminous intensity | candela | cd |
Table 1: the SI base units
You like the SI units so much that you refuse to use any other unit. A derived unit such as the joule (J), the newton (N) or the ohm is expressible in base units as kg m^2 / s^2, kg m / s^2 and kg m^2 / s^3 A^2. So during the trip you write down every unit you come across together with its definition. Some definitions depend on earlier ones, like Pa = N / m^2.
With the definitions at hand you no longer put up with 60 firkins / microfortnights or 63 km / h, because you can always convert them to SI units. Calculations like 100 m + 1.3 km and 7 N * 8 ohm become easy too.
You are given the unit definitions and a list of computations. Convert the result of every computation to SI base units.
The input follows this syntax, where ? denotes zero or one, + denotes one or more, and * denotes zero or more.
power ::= { integer from 2 to 4 }
unit ::= { upper or lower case English letter }+
dimension ::= unit ['^' power]?
size ::= { floating-point number } [' ' dimension]* [' /' [' ' dimension]+]?
operator ::= '+' OR '-' OR '*'
expression ::= size ' ' operator ' ' size
definition ::= unit ' = ' size
Tokens inside a line are separated by single spaces. The division sign / is a token of its own and has a space on both sides, and so does the = of a definition. A floating-point number is written like 63, 1.3, -2.5 or 1E5.
The first line holds the number of new units U. The next U lines hold one unit definition each. After them comes a line with the integer N, and then N lines with one expression or one size each.
For each computation print one line with the result converted to SI base units. If the two sides of a + or a - have different dimensions the answer cannot be computed, so print Incompatible on that line.
Print a line in this format.
e, the sign of the exponent, and the exponent in two digits or more. This is what printf("%.5e", x) in C and "%.5e" % x in Python produce, for example 1.40000e+03 or -2.50000e-03. If the value is zero, print 0.00000e+00 with no sign./ next, then those units in the same order with the absolute value of their exponents.^.