#include <bits/stdc++.h>
using namespace std;

const int MAX_M=10010,MAX_T=1300;

int N,M,r,q,t,n,m,s,ts,te;
vector<vector<int>> record(MAX_M,vector<int>(MAX_T));


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	while(cin >> N >> M,N){
		for (int i=0;i<M;++i){
			fill(record[i].begin(),record[i].end(),0);
		}
		cin >> r;
		for (;r--;){
			cin >> t >> n >> m >> s; --m;
			if (s) ++record[m][t];
			else --record[m][t];
		}
		for (int i=0;i<M;++i){
			for (int j=0;j<MAX_T-1;++j) record[i][j+1]+=record[i][j];
			for (int j=0;j<MAX_T;++j) record[i][j]=min(1,record[i][j]);
			for (int j=0;j<MAX_T-1;++j) record[i][j+1]+=record[i][j];
		}
		cin >> q;
		for (;q--;){
			cin >> ts >> te >> m; --m;
			cout << record[m][--te]-record[m][--ts] << '\n';
		}
	}
}
