409823: GYM103797 J Judge Crush

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Judge Crushtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

After every GRUPODEESTUDOSPARAPROGRAMACAO++ (study group with a catchy name) contest in vjudge, the contest setters, who call themselves "judges", like to check the precision of the contestants. Since Ana Livia always finishes her upsolving in less than a minute and has a big crush on one of the judges, she decided to write a program that tells the total number of submissions of the contest. To get more accurate data, she will actually only count the incorrect submissions on the problems that the contestant eventually got a correct submission.

Unfortunately, the "Rank" section is not working properly, so she is getting her data through the "Status" section. There, she can only see the submissions and its verdict one by one. The submission appears along with the contestants ID, which are all different and between $$$1$$$ and the number of contestants, and the problem ID, which are all different and between $$$1$$$ and the number of problems. The possible verdicts are WA (Wrong Answer), RTE (Run Time Error), TLE (Time Limit Exceeded), MLE (Memory Limit Exceeded) and AC (Accepted, the only verdict to a correct submission).

To impress her secret crush even more, she decided to make a program that counts the submissions for a contiguous range of problems and a contiguous range of contestants, following the order of their IDs. To test her program, she is going to make some queries of ranges to check its response. Can you help her, in the name of love?

Input

The first line consists of two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N, M \leq 500$$$) — the number of contestants and the number of problems, respectively.

The next line consists of a single integer $$$S$$$ ($$$1 \leq S \leq 2 \times 10^5$$$) — the number of submissions.

Each of the next $$$S$$$ lines consists of $$$2$$$ integers $$$C$$$ and $$$P$$$ ($$$1 \leq C \leq N$$$ and $$$1 \leq P \leq M$$$) and a string $$$V$$$ — the contestants ID, the problems ID and the verdict of the submission (WA, RTE, TLE, MLE or AC). The submissions are given in their chronological order. If a contestant gets an AC verdict on a problem, he no longer sends submissions to that problem.

The next line consists of a single integer $$$Q$$$ ($$$1 \leq Q \leq 2 \times 10^5$$$) — the number of queries.

Each of the next $$$Q$$$ lines consists of $$$4$$$ numbers, $$$C_1$$$, $$$P_1$$$, $$$C_2$$$ and $$$P_2$$$ ($$$1 \leq C_1 \leq C_2 \leq N$$$ and $$$1 \leq P_1 \leq P_2 \leq M$$$) — a query to check the number of incorrect submissions until a correct submission from contestant with ID $$$C_1$$$ to contestant with ID $$$C_2$$$ and from problem with ID $$$P_1$$$ to problem with ID $$$P_2$$$.

Output

For each query, print one line with the response of Ana Livia's program.

ExamplesInput
2 2
7
1 2 AC
2 2 WA
2 2 AC
2 1 RTE
2 1 TLE
2 1 TLE
2 1 AC
2
1 1 2 2
1 2 2 2
Output
4
1
Input
3 3
21
1 3 MLE
1 3 AC
1 2 WA
1 2 WA
1 2 WA
1 2 WA
1 2 WA
1 2 WA
1 2 WA
1 2 AC
2 1 MLE
2 1 MLE
2 1 MLE
2 1 AC
2 2 AC
3 2 TLE
3 2 TLE
3 2 TLE
3 2 TLE
3 1 AC
3 3 AC
2
1 2 3 3
3 1 3 3
Output
8
0

加入题单

算法标签: