//14:17
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int, int> > vii;
typedef long long ll;
int per[10100][1000];
int ln[10100];//???????????¨????????°?????°
int main(){
	
	//stu[m] [0]?????? t[1]PC n[2]?????°?????? s
	while(1){
		vii stu[10100];
		int n,m;
		int r;
		cin >> n >> m;
		if(n==0&&m==0) break;
		cin >> r;
		rep(i,m){
			ln[i]=0;
			rep(j,1000){
				per[i][j]=0;
			}	
		}
		rep(i,r){
			int t,n,m,s;
			cin >> t >> n >> m >> s;
			m-=1;
			stu[m].pb(make_pair(t,s));
			ln[m]++;
 		}
 		rep(i,m){
 			int ms = 0;
 			int p = 0;
 			rep(j,ln[i]){
 				if(stu[i][j].se==1){
 					if(ms==0){
 						per[i][p++] = stu[i][j].fi;
 					}
 					ms++;
 				}else if(stu[i][j].se==0){
 					if(ms==1){
 						per[i][p++] = stu[i][j].fi;
 					}
 					ms--;
 				}
 			}
 			ln[i]=p;
 		}
 	// 	cout << "debug" << endl;
 	// 	rep(i,m){
		// 	rep(j,ln[i]){
		// 		cout << "j:"<<j<<""<< per[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		// cout << endl;
		int q;
		cin >> q;
		rep(i,q){
			int ans =0;
			int ts,te,m;
			cin >> ts >> te >> m;
			m--;
			for(int j=0;j<ln[m]/2;j++){
				ans += max(0,min(te,per[m][j*2+1])-max(ts,per[m][j*2]));
			}
			// cout << "ans" << endl;
			cout << ans << endl;
		}
		
	}
	return 0;
}