// Aizu 1148: Analyzing Login/Logout Records
// 2017.9.16 bal4u@uu

#include <stdio.h>

typedef struct { int t, pc, m, s; } R;
R rd[1005];

int main()
{
	int n, m, r, q, i, j, ts, te, t, ans, cnt;

	while (scanf("%d%d", &n, &m) && n) {
		scanf("%d", &r); 
		for (i = 0; i < r; i++) scanf("%d%d%d%d", &rd[i].t, &rd[i].pc, &rd[i].m, &rd[i].s);
		scanf("%d", &q); 
		for (i = 0; i < q; i++) {
			scanf("%d%d%d", &ts, &te, &m);
			for (ans = t = cnt = 0, j = 0; j < r; j++) {
				if (rd[j].t >= te) { if (t > 0) ans += te - t; break; } 
				if (rd[j].m != m) continue;
				if (rd[j].s) {
					cnt++; if (t == 0) { if (rd[j].t < ts) t = ts; else t = rd[j].t; }
				} else {   // lg[j].s == 0
					if (--cnt == 0) {
						if (rd[j].t > ts && t > 0) ans += rd[j].t - t;
						t = 0;
					}
				}
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}