// Original C++ solution (slower):
#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;

		}

	}

}

// Optimized solution to the same problem (faster):
#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;

		int r; cin >> r;

		vector<int> t(r), n(r), m(r), s(r);

		for (int i = 0; i < r; i++)

			cin >> t[i] >> n[i] >> m[i] >> s[i];

		int q; cin >> q;

		while (q--) {

			int ts, te, _m; cin >> ts >> te >> _m;

			int x = 0, start, end, ans = 0;

			for (int i = 0; i < r; i++) {

				if (m[i] != _m) continue;

				if (s[i]) {

					if (x == 0) start = t[i];

					x++;

				}

				else {

					x--;

					if (x == 0) {

						end = t[i];

						ans += max(0, min(te, end) - max(ts, start));

					}

				}

			}

			cout << ans << endl;

		}

	}

}

// Fastest known solution for this problem:
#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<cstdio>

#include<cstring>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

#define REP(n) rep(i,n)

#define all(n) n.begin(),n.end()



const int MAXN = 1000, MAXM = 10000, MAXR = 1000, MAXQ = 50, MAXT = 1260;



int mem[MAXM + 1][MAXT + 1];



const int LOGIN = 1, LOGOUT = 0;

int main()

{

    int n, m;

    while(cin >> n >> m && n)

    {

        memset(mem, 0, sizeof(mem));

        int r; cin >> r;

        int rt, rn, rm, rs;

        REP(r)

        { 

            cin >> rt >> rn >> rm >>  rs;

            if(rs == LOGIN)

                for(int j = rt; j <= MAXT; j++) mem[rm][j] += 1;

            else

                for(int j = rt; j <= MAXT; j++) mem[rm][j] -= 1;

        }

        int q; cin >> q;

        REP(q)

        {

            int ts, te , qm;

            cin >> ts >> te >> qm;

            int ans = 0;

            

            for(int j = ts; j < te; j++)

                if(mem[qm][j] > 0) ans++;



            cout << ans << endl;

        }

                

    }

    return 0;

}