Qcjj has been playing a role-playing game ''Flame blast magician master'' recently, in which the player will play as a hero who uses skills to attack monsters.
The world of the game can be regarded as a plane constituted by a two-dimensional coordinate of size

. The lower left corner is the coordinate origin
)
.
At the beginning of the game, there are

monsters. Among these monsters, the

-th monster is located in
)
with the initial HP(health point)

.
There may be multiple monsters in the same position on this two-dimensional axis.
When the player hits the monster with a skill attack, the monster's HP will be reduced by
When a monster's HP

, the monster will die immediately, and the player will receive the score

.
The killed monster will quit the game permanently.
Players can use the unique hero skill ''Flame Blast'' , generating a burning wall, perpendicular or parallel to the axis, attacking certain consecutive rows or columns.
As shown in the figure, for example, there are three monsters

in the two-dimensional coordinate axis.
Assume that the initial HP of those three monsters is all equal to

and the killing score is all equal to

. Qcjj uses the ``Flame Blast'' skill twice.
Suppose the wall created by the first use of the skill is horizontal to the

axis, Attacking monsters

downwards from the top infinite distance. The

monster HP is reduced to

. Since none of the monsters have been killed yet, the player's

at this moment is

points.Then the second skill creating the wall perpendicular to the

axis, attack monster

from the far left infinity to the right. The skill successfully hits

, causing the hp of

to be reduced to

, and the player gets a total of

points for killing the monster

. At this time, the player's

is

.
The entire process of the game can be abstracted as

events. Events are divided into three types. The first two events allow the player to use the `Flame Blast' skill to create a horizontal or vertical wall with the

axis as described earlier, which is used to attack monsters. The third event is the appearance of a monster at a specific position on the axis plane.
Now you need to write an instant game plugin that outputs the player's current score after each event.
In order to ensure the ''immediacy'' of your game plug-in, a part of the input data will be encrypted, forcing online decryption, the decryption method is described in ''input description''.