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

#include <stdio.h>
#define MAX_M (10000)
#define FIX_TIME (540)

int main(int argc, const char * argv[]) {
    
    
    while (1) {
        int N,M,r,t,n,m,s,q,ts,te;
        int i,j;
        int student[MAX_M][740];
        
        
        
        scanf("%d %d",&N,&M);
        
        for (i=0; i<M; i++) {
            for (j=0; j<740; i++) {
                student[i][j] = 0;
            }
        }
        
        if (N==0&&M==0) {
            break;
        }
        
        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 (student[m-1][j] == 1) {
                        break;
                    }
                    student[m-1][j-FIX_TIME] = 1;
                    j--;
                }
            } else if (s == 1){//login
                student[m-1][t-FIX_TIME] = 1;
            }
        }
        
        scanf("%d",&q);
        
        for (i=0; i<q; i++) {
            scanf("%d %d %d",&ts,&te,&m);
            
            int tsum=0;
            for (j=ts-FIX_TIME; j<=te-FIX_TIME; j++) {
                if (student[m-1][j] == 1) {
                    tsum++;
                }
            }
            
            printf("%d\n",tsum);
            
        }
        
    }
    return 0;
}