#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<deque>
using namespace std;
#define pb push_back
typedef long long lint;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
int main(){
	int n,m,r,q,i,j;vector <int> out;
	while(1){
		cin>>n>>m;
		if(n==0) break;
		vector<vector<int> > sei(m+1,vector<int>(1300,0));
		int r,q;
		cin>>r;
		for(i=0;i<r;i++){
			int t1,n1,m1,s;cin>>t1>>n1>>m1>>s;
			if(s==1) sei[m1][t1]++;
			else sei[m1][t1]-=1;
		}
		for(i=0;i<=m;i++){
			for(j=500;j<=1295;j++){
				sei[i][j]+=sei[i][j-1];
			}
		}
		cin>>q;
		for(i=0;i<q;i++){
			int s2,e,m2;cin>>s2>>e>>m2;
			int ret=0;
			for(j=s2;j<e;j++) if(sei[m2][j]>0) ret++;
			out.pb(ret);
		}
	}
	for(i=0;i<out.size();i++) cout<<out[i]<<endl;
	return 0;
}