Time limit: 1 second
Memory limit: 256 MB
Taymur, who loves electricity and programming, decided to take over the electrical control system of a store. The store manager, who still didn't trust Timur, gave him a task to test him! He gave Timur the task of calculating the electricity cost of the store's lamps.

Image caption

The store has
n
n lamps, numbered from 1 to
n
n. The lamps in this store are of two types: sensor and key:

Sensor lamps have a delay of
t
i
t
i
​
. This value means that the lamp turns on from the moment it receives a signal. If there is no other signal to turn on within
t
i
t
i
​
seconds after receiving the signal, the lamp turns off.
Key lamps stay on as long as their switch is on, and turn off if their switch is off. These bulbs have exactly one switch.
In addition to the aforementioned characteristics, each bulb has a value
p
i
p
i
​
that indicates its power. The
i
i-th bulb consumes
p
i
p
i
​
units of energy for each second it is on.

The way electricity costs are calculated for bulbs is also in steps. More precisely, the price of electricity has
k
k steps, and the
i
i-th step has two characteristics
E
i
E
i
​
and
P
i
P
i
​
, which respectively indicate the maximum amount of energy that can be placed in this step and the price per unit of energy for that step.

To calculate the price of electricity in a month, Timur must first calculate how much energy all the lamps together have consumed (we will consider this value as
E
E). Then he finds the smallest step
i
i for which
E
i
E
i
​
is not less than the amount consumed for the entire month (
E
≤
E
i
E≤E
i
​
). After that, he obtains the amount of each unit of energy in that month, which is equal to
P
i
P
i
​
. As a result, the total price of energy consumed in that month will be equal to
P
i
×
E
P
i
​
×E.

Timur, who understood the price calculation system well, quickly got to work and got the list of reports of turning on and off the lamps from the store manager and, to prove his ability, decided to use it to calculate the electricity cost for the previous month.

Let's assume that all the lamps are off at the beginning.

Input
The first line of the input contains the number
n
n, which indicates the number of lamps. The next
i
ith line of the
n
n lines contains the description of the
i
ith lamp. The format of the description of each lamp will be as follows:

Lamp input format
The lamp input format is in one of the following forms:

SWITCH p_i
SENSOR p_i t_i
Plain text
The first line indicates a switch-type lamp with a power of
p
i
p
i
​
and the second line indicates a sensor lamp with a power of
p
i
p
i
​
and a delay of
t
i
t
i
​
.

1
≤
n
≤
100
1≤n≤100
1
≤
p
i
≤
200
1≤p
i
​
≤200
1
≤
t
i
≤
100
1≤t
i
​
≤100

The next line contains the number
k
k, which indicates the number of electricity price steps. In the
ith line of
k
k, the next line contains two values ​​
E
i
E
i
​
and
P
i
P
i
​
, respectively, which indicate the maximum energy of the
ith step and the price of each unit of energy in that step.

1
≤
k
≤
10
1≤k≤10
1
≤
E
i
≤
6
×
1
0
10
1≤E
i
​
≤6×10
10

1
≤
P
i
≤
1
0
6
1≤P
i
​
≤10
6

It is guaranteed that the values ​​of
E
i
E
i
​
and
P
i
P
i
​
are in ascending order at the input, and also that the value of the last
E
i
E
i
​
is at least as large as the total energy consumption.

In the next line, the number
m
m is given, which indicates the number of reports, and in each of the
m
m lines, there is one report. The format of each report will also be as follows:

Input format of each report
The input format of each report is as follows:

LAMP_ID TIME
Plain text
Where LAMP_ID indicates the number of the lamp to which the report belongs and TIME indicates the time when the change occurred. Each report is related to a lamp and if the lamp in question is of the sensor type, this report means that a signal has been sent to this sensor and if it is of the key type, it means that the state of the key of that lamp has changed (if the lamp is on, it will be off and vice versa).

The format of TIMEs is also guaranteed to be as follows:

DD hh:mm:ss
Plain text
Where DD, hh, mm and ss indicate the day, hour, minute and second of the occurrence of that event, respectively.

1
≤
m
≤
1

000
1≤m≤1 000
1
≤
L
A
M
P
I
D
≤
n
1≤LAMP
I
​
D≤n
1
≤
D
D
≤
31
1≤DD≤31
0
≤
h
h
≤
23
0≤hh≤23
0
≤
m
m
≤
59
0≤mm≤59
0≤s
s
≤
59
0≤ss≤59
If a lamp was on until 23:59:59 on the 31st, we assume that it will be turned off at this time. We also assume that the month we are in has 31 days and its last moment is 23:59:59 on the 31st.

The reports are guaranteed to arrive in the order of their TIME in the input.

Output
The output of your program should include a line showing the amount of electricity bill for that month.

Subproblems
Subproblem Score Constraints
1 30 lamps are only switch type
2 50 lamps are only sensor type
3 20 no additional constraints
Example
Sample Input 1
2
SWITCH 1
SENSOR 2 2
4
2 1
5 3
11 4
15 5
4
1 01 00:00:00
1 01 00:00:05
2 01 00:00:10
2 01 00:00:11
Plain text
Sample Output 1
44
Plain text
Sample Input 2
2
SWITCH 19
SENSOR 200 11
4
190864635 992101
776902253 992469
785256700 992509
1071360000 999462
5
1 13 21:54:16
2 16 02:40:30
1 21 12:28:38
2 25 22:11:09
1 28 22:11:26
Plain text
Sample output 2
17402369233425
Plain text
Sample input 3
5
SWITCH 192
SWITCH 151
SWITCH 114
SWITCH 130
SWITCH 199
5
1747205084 11955
2653259616 296990
2669525672 525837
2674590960 538566
2678400                                               c++