#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0) break;
		vector< vector<short> > a(M, vector<short>(1300));
		int r; cin >> r;
		while (r--) {
			int t, n, m, s; cin >> t >> n >> m >> s;
			m--;
			a[m][t] += (s ? 1 : -1);
		}
		vector< vector<short> > s(M, vector<short>(1300));
		for (int m = 0; m < M; m++)
			for (int t = 1; t < 1300; t++)
				s[m][t] = s[m][t - 1] + a[m][t - 1];
		int q; cin >> q;
		while (q--) {
			int ts, te, m; cin >> ts >> te >> m;
			m--;
			int cnt = 0;
			for (int t = ts + 1; t <= te; t++)
				if (s[m][t]) cnt++;
			cout << cnt << endl;
		}
	}
}