import std.stdio;
import std.algorithm;
import std.range;

enum Size = 1260 - 540 + 1;

void main()
{
    uint N, M;
    while({readf("%s %s\n", &N, &M); return N;}())
    {
        uint[][] imos;
        foreach(i; 0 .. M)
            imos ~= new uint[Size];

        uint r;
        readf("%s\n", &r);
        foreach(i; 0 .. r){
            uint t, n, m, s;
            readf("%s %s %s %s\n", &t, &n, &m, &s);
            imos[m-1][t-540] += s ? 1 : -1;
        }

        foreach(i; 0 .. M){
            uint sum = 0;
            foreach(ref e; imos[i]){
                sum += e;
                e = sum;
            }
        }

        uint q;
        readf("%s\n", &q);
        foreach(i; 0 .. q){
            uint ts, te, m;
            readf("%s %s %s\n", &ts, &te, &m);
            imos[m-1][ts-540 .. te-540].filter!"a".walkLength().writeln;
        }
    }
}