#K59392. Calculate Final Hay Amount
Calculate Final Hay Amount
Calculate Final Hay Amount
You are given an initial amount of hay and a sequence of instructions. Each instruction is in the form ADD x or MUL x, which respectively add to or multiply the current hay amount. For each test case, execute all the instructions in order and output the final amount of hay obtained. Mathematically, starting with \( h_0 \), for each instruction:
\( \text{if } \text{instruction} = ADD\, x: \quad h = h + x \)
\( \text{if } \text{instruction} = MUL\, x: \quad h = h \times x \)
Input is through standard input and output must be written to standard output.
inputFormat
The first line of input contains an integer \( T \) representing the number of test cases. For each test case, the first line contains two integers \( m \) and \( h_0 \), where \( m \) is the number of instructions and \( h_0 \) is the initial hay amount. The following \( m \) lines each contain one instruction in one of the following two formats: ADD x or MUL x, where \( x \) is an integer.
outputFormat
For each test case, output one line containing the final hay amount after applying all the instructions.
## sample3
3 10
ADD 5
MUL 2
ADD 3
2 7
MUL 3
ADD 4
2 5
ADD 0
MUL 3
33
25
15
</p>