#include <stdio.h>
#include <string.h>

/*typedef struct {
	int login_student;
	int login_time;
} pc_t;*/

int pc_num,student_num;
/*pc_t pc[1000];*/
int student_used[10000][2000];
int student_used2[10000][2000];

int main(void) {
	int kiroku_num;
	int query_num;
	int i,j;
	int k_zikoku,k_pc,k_student,k_type;
	int q_start,q_end,q_student;
	while(1) {
		scanf("%d%d",&pc_num,&student_num);
		if(pc_num==0 && student_num==0)break;
		memset(student_used,0,sizeof(student_used));
		memset(student_used2,0,sizeof(student_used2));
		scanf("%d",&kiroku_num);
		for(i=0;i<kiroku_num;i++) {
			scanf("%d%d%d%d",&k_zikoku,&k_pc,&k_student,&k_type);
			k_pc--;k_student--;
			if(k_type==1) {
				/*pc[k_pc].login_student=k_student;
				pc[k_pc].login_time=k_zikoku;*/
				student_used[k_student][k_zikoku]++;
			} else {
				student_used[k_student][k_zikoku]--;
			}
		}
		for(i=0;i<student_num;i++) {
			for(j=1;j<2000;j++) {
				student_used[i][j]+=student_used[i][j-1];
				if(student_used[i][j]>0)student_used2[i][j]=1;
				student_used2[i][j]+=student_used2[i][j-1];
			}
		}
		scanf("%d",&query_num);
		for(i=0;i<query_num;i++) {
			scanf("%d%d%d",&q_start,&q_end,&q_student);
			q_student--;
			printf("%d\n",student_used2[q_student][q_end-1]-
				student_used2[q_student][q_start-1]);
		}
	}
	return 0;
}