Calculator

Time Limit: 5000ms
Memory Limit: 131072KB
This problem will be judged on HDU. Original ID: 5238
64-bit integer IO format: %I64d      Java class name: Main

Description

Sakura has invented a new kind of calculator that can evaluate expressions. This calculator maintains a serial of operators and numbers inside. All these numbers and operators form an ordered table. For example

$*4 \quad + 2 \quad \hat{} 3 \quad + 8 \quad * 6$

is a possible table. The calculator also supports the following two operations.

1. 1 $x$.

This corresponds to the evaluation operation. For instance, if $x=2$, together with the table being the one described above, the calculator will output

$ ((((2*4)+2)^3)+8)*6=6048.$

As for $x=3$, it will output

$((((3*4)+2)^3)+8)*6=16512.$

2. 2 $p$ $cx$.

This corresponds to the modification operation. The calculator will change the $p$-th term in the expression to $cx$. Here $c$ denotes an operator while $x$ denotes a number.

For example, if $p=3$ and $cx=*5$, the expression will become

$*4 \quad + 2 \quad *5 \quad + 8 \quad * 6.$

Now you are asked to implement this calculator. However, for technical reasons, you should just output the result modulo 29393. It is guaranteed that, in all terms appeared in the input data, $c \in \{+, *, \hat{} \}$, $0 \le x < 29393$.

Input

The first line contains an integer $T$($T \le 10$), denoting the number of test cases. It is guaranteed that $1 \le n, m \le 50000$.

For each test case, the first line contains two numbers $n, m$. $n$ denotes the number of terms in the expression, $m$ denotes the number of operations.

In the following $n$ lines, each line contains a term in style of $cx$, denotes each term in the initial table.

In the following $m$ lines, each line contains an operation. It must in style of ''$1 \quad x$'' or ''$2\quad p \quad cx$''.

Output

For each test case, output Case #t: in a single line to represent the $t$-th case.
Then in each test case, output the result modulo 29393 for each evaluation operation.

Sample Input

2
5 4
*4
+2
^3
+8
*6
1 2
1 3
2 3 *5
1 3
4 3
*4
^4
+4
*10
1 1
2 3 ^4
1 1

Sample Output

Case #1:
6048
16512
468
Case #2:
2600
4107
P

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .