A university runs a computer literacy course. In its computer system, the login/logout records of every PC for one day are stored in a file. A student may use two or more PCs at the same time, but nobody can log in to a PC that another student has logged in to and not yet logged out of.
Write a program that, for a given time period (for example, a laboratory class), computes the total time during which a student was using at least one PC, based on the records in the file.
The following is an example of login/logout records.
For a query such as "Give the usage of student 1 between 13:00 and 14:30", the program should answer "55 minutes": the sum of 45 minutes from 13:00 to 13:45 and 10 minutes from 14:20 to 14:30.
The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space (0 0). The number of datasets never exceeds 10.
Each dataset has the following format.
N M
r
record1
...
recordr
q
query1
...
queryq
On the first line, $N$ and $M$ are the number of PCs and the number of students, respectively. $r$ is the number of records and $q$ is the number of queries. These four integers satisfy:
Each record consists of four space-separated integers $t\ n\ m\ s$.
$s$ is 0 or 1. If $s$ is 1, the line means that student $m$ logged in to PC $n$ at time $t$; if $s$ is 0, it means that student $m$ logged out of PC $n$ at time $t$. Time is expressed as the number of minutes elapsed since 0:00 of the day. $t$, $n$, and $m$ satisfy:
You may assume the following about the records.
Each query consists of three space-separated integers $t_s\ t_e\ m$.
It represents "the usage of student $m$ between $t_s$ and $t_e$". $t_s$, $t_e$, and $m$ satisfy:
For each query, print one line containing a decimal integer: the usage time in minutes. Output lines must not contain any character other than this number.