Given several prefix expressions, each represents a function. The expression has at most 4 types of operations and 5 variables, described below.
We explain the 4 operations using infix:
1. Addition. 'a+b' means a plus b, in which a, b are integers.
2. Negation. '-a' means a*(-1), in which a is an integer.
3. Multiplication. 'a*b' means a times b, in which a, b are integers.
4. Function call. 'f@a' means return the value f(a), in which f is a function and a is an integer.
For variables, they are all integers, and the 5 variables are A, B, C, D, and X, respectively. For A, B, C, and D, you will get their values from input. For X, it is the parameter that you gave the function.
The function name will be a lowercase letter. Given the function name and the prefix expression of each function. Now here are q queries: Given the function name and the parameter for the function, and the value of A, B, C, and D, please output the calculation result.
For sample input 2, here are the syntax trees for the 4 functions.
Note the parameter X for the functions are different. For example, it's 1 for f and it's 5 for g, in the second query.
For the second type operation, negation, it has only one child in the syntax tree, which is the right child.
In this problem, calling functions often cause an error since the calculation process may not stop because of repeating calling the same functions. For example, the first query in sample input 2 would call function h first, then the function h would call function k. Function k would then call function h, and never ends. In this case, you should stop the process and print 'Error'.
The first line contains two integers, n and q, which means there are n functions and q queries.
The following n lines each contain a lowercase letter representing the function name, and a string representing the prefix expression, separated by space.
The last q lines each contain a lowercase letter and five integers, separated by spaces, each representing the function name, the parameter X, A, B, C, and D.
Constraints:
1 ≤ n ≤ 26
1 ≤ q ≤ 100
-1000 ≤ A, B, C, D, X ≤ 1000
The expression would not contain over 200 characters.
For cases 1~4, it is guaranteed that no error occurs during process, and no negation operation.
For cases 5~8, it is guaranteed that no error occurs during process.
For other cases, no further constraints.
An integer represents the calculation result. Since the answer could be large, please output the answer modulo 998244353.
Note
Since the answer should modulo 998244353, you should take the remainder after every operation. Since the result of taking the remainder must be non-negative, the result should add 998244353 if it is negative after modulo. Be free to use the following function: