#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 1261;

int main() {
	int N, M;
	while(cin >> N >> M, N) {
		vector<vector<int>>	log(M+1, vector<int>(MAX, 0));	
		int R;
		cin >> R;
		int t, n, m, s;	
		rep(i, R) {
			cin >> t >> n >> m >> s;	
			log[m][t] += (s == 1) ? 1 : -1;
		}

		REP(i, 1, M+1) {
			REP(j, 540, MAX) {
				log[i][j] += log[i][j-1];
			}
		}

		int Q;
		cin >> Q;
		int ts, te;	
		rep(i, Q) {
			cin >> ts >> te >> m;	
			int ans = 0;	
			for(int i = ts; i < te; ++i) {
				if(log[m][i] > 0) ++ans;	
			}
			cout << ans << endl;
		}
	}
	return 0;
}