#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int sum[10000][1280];
int main() {
	int N, M, r;
	while (scanf("%d%d", &N, &M), N) {
		scanf("%d", &r);
		memset(sum, 0, sizeof(sum));
		rep(i, r) {
			int t, n, m, s; scanf("%d%d%d%d", &t, &n, &m, &s);
			if (s)sum[m - 1][t]++;
			else sum[m - 1][t]--;
		}
		rep(i, M) {
			for (int j = 540; j <= 1260; j++)
				sum[i][j] += sum[i][j - 1];
		}
		int q; scanf("%d", &q);
		rep(i, q) {
			int ts, te, m; scanf("%d%d%d", &ts, &te, &m);
			int cnt = 0;
			for (int j = ts; j < te; j++) {
				if (sum[m - 1][j])cnt++;
			}
			printf("%d\n", cnt);
		}
	}
}