In TEKSTER, an environment for solving elementary-school word problems, a task is written as text in which the input data are marked by variables of the form #lowercase-latin-letter. For example:
Two hikers set out at the same moment from settlements A and B toward each other and met after #a=3 hours. The hiker from settlement A walked #b=4 km every hour, and the hiker from settlement B walked #c=5 km every hour. What was the distance between the settlements?
When solving a task with TEKSTER, at each step the student may perform one addition, subtraction, or multiplication, using the input data and the intermediate results already obtained. The environment records all of the student's operations, marking intermediate results with uppercase Latin letters.
From the task text and the operations, find the numerical result of the last operation.
The first line of the input contains the task text (up to 250 characters). The second line contains the number of solution steps the student performed, and each of the following lines contains one solution step.
You may assume that the symbol # appears in the task text only to present variable values, in the form
#lowercase-latin-letter=value
and the values are natural numbers from 1 to 999. At least one variable is assigned a value in the text, and no variable is assigned a value more than once.
The solution contains at least one operation. The solution lines contain only valid equalities of the form
uppercase-latin-letter
=latin-letteroperatorlatin-letter
where the right-hand side always consists of already-known quantities and the operator is +, -, or *. No uppercase Latin letter appears on the left-hand side of a solution step more than once. However, the student may also have performed unnecessary operations. The absolute value of every operation's result does not exceed $1,000,000$.
Output a single integer on one line --- the result of the last operation performed by the student.