//
//  main.c
//  Logout Records
//
//  Created by x15071xx on 2016/06/20.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>

int main (int argc, const char * argv[]){
    int i,j,k;
    while(1) {
        int N,M,r,t,n,m,s,q,ts,te;
        int pc[1000][720];
        
        scanf("%d %d",&N,&M);
        
        if (N==0&&M==0) {
            break;
        }
        
        for (i=0; i<N; i++) {
            for (j=0; j<520; j++) {
                pc[i][j] = 0;
            }
        }
        
        scanf("%d",&r);
        
        for (i=0; i<r; i++) {
            scanf("%d %d %d %d",&t,&n,&m,&s);
            
            if (s == 0) { //logout
                j=t;
                while (1) {
                    if (pc[n-1][j] == m-1) {
                        break;
                    }
                    pc[n-1][j-520] = m-1;
                    j--;
                }
            } else if (s == 1){//login
                pc[m-1][t-520] = m-1;
            }
        }
        
        scanf("%d",&q);
        
        for (i=0; i<q; i++) {
            scanf("%d %d %d",&ts,&te,&m);
            
            int sum=0;
            ts = ts - 520;
            te = te - 520;
            for (k=0; k<N; k++) {
                for (j=ts; j<te; j++) {
                    if (pc[m-1][j] == m-1) {
                        sum++;
                    }
                }
            }
            
            printf("%d\n",sum);
            
        }
        
    }
    
    return 0;
}