#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

int dp[10001][722];

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        memset(dp, 0, sizeof dp);
        int r;
        cin >> r;
        for (int i=0; i<r; ++i) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            if (s == 1) {
                dp[m][t-540] += 1;
            } else {
                dp[m][t-540] -= 1;
            }
        }
        for (int i=1; i<=M; ++i) {
            for (int j=1; j<722; ++j) {
                dp[i][j] = dp[i][j-1] + dp[i][j];
            }
        }
        int q;
        cin >> q;
        for (int i=0; i<q; ++i) {
            int ts, te, m;
            cin >> ts >> te >> m;
            int cnt = 0;
            for (int j=ts; j<te; ++j) {
                cnt += (0 < dp[m][j-540]);
            }
            cout << cnt << endl;
        }
    }
    return 0;
}