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

int s[10000][750];
signed main() {
	int a, b, c; 
	while (cin >> a >> b, a | b) {
		memset(s, 0, sizeof(s));
		cin >> c;
		for (int d = 0; d < c; d++) {
			int e, f, g, h; scanf("%d%d%d%d", &e, &f, &g, &h); g--;
			e -= 540;
			if (h) {
				s[g][e]++;
			}
			else {
				s[g][e]--;
			}
		}
		for (int d = 0; d < b; d++) {
			int k = 0;
			for (int e = 0; e < 750; e++) {
				k += s[d][e];
				s[d][e] = k;
			}
		}
		int d; cin >> d;
		for (int e = 0; e < d; e++) {
			int f, g, h; scanf("%d%d%d", &f, &g, &h); f -= 540; g -= 540; h--;
			int sum = 0;
			for (; f < g; f++) {
				if (s[h][f])sum++;
			}
			cout << sum << endl;
		}
	}
}