#K65707. Water Dispenser Simulation

    ID: 32257 Type: Default 1000ms 256MiB

Water Dispenser Simulation

Water Dispenser Simulation

You are given a simulation of a water dispenser. The dispenser accepts three types of commands: start, stop, and reset. Initially, the dispenser is not dispensing water.

When a start command is issued, the dispenser begins a session. If a stop command is encountered while a session is active, an amount of water equal to s is dispensed and the session ends. If a reset command is encountered, any ongoing session is cancelled. Any stop command without a preceding active start is ignored.

The amount s is provided for each test case along with additional parameters (including a parameter w that is not used in the calculation) and a sequence of commands.

Mathematically, each successful dispensing (i.e. a stop command following a start command without interruption) adds s units of water to the total. In LaTeX form, if you let \(D\) be the total water dispensed and there are \(k\) valid sessions, then:

\[ D = k \times s \]

inputFormat

The input is read from stdin and has the following format:

T
s1 w1 c1
command1,1 command1,2 ... command1,c1
s2 w2 c2
command2,1 command2,2 ... command2,c2
...

The first line contains a single integer T representing the number of test cases. For each test case, the first line contains three integers: s (the water amount dispensed per session), w (a parameter not used in the simulation), and c which is the number of commands. The following line contains c space‐separated commands.

outputFormat

For each test case, output a single line containing the total amount of water dispensed. The output is written to stdout.

## sample
2
5 1000000 4
start stop start stop
2 500000 6
start stop reset start stop start
10

4

</p>