#include<iostream>
#include<cstring>
using namespace std;
int x[10000][1440],y[10000],n,m,r,q,i,j,a,b,c,d,s;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n >> m >> r; if (n == 0) { break; }
		for (i = 0; i < r; i++) {
			cin >> a >> b >> c >> d;
			if (d == 1) {
				y[c]++;
				for (j = a; j < 1440; j++) {
					x[c][j] = 1;
				}
			}
			else {
				y[c]--;
				if (y[c] == 0) {
					for (j = a; j < 1440; j++) {
						x[c][j] = 0;
					}
				}
			}
		}
		cin >> q;
		for (i = 0; i < q; i++) {
			s = 0;
			cin >> a >> b >> c;
			for (j = a; j < b; j++) {
				if (x[c][j] == 1) { s++; }
			}
			cout << s << endl;
		}
	}
}