// Original C++ solution (slower):
//14:17

#include <iostream>

#include <string>

#include <map>

#include <vector>

#include <algorithm>

#include <queue>

using namespace std;



#define REP(i,k,n) for(int i=k;i<n;i++)

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



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

#define INF 1<<30

#define mp make_pair

#define pb push_back



#define fi first

#define se second



#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)



typedef vector<int> vi;

typedef vector<vi> vvi;

typedef pair<int,int> pii;

typedef vector<pair<int, int> > vii;



typedef long long ll;

int per[10100][1000];

int ln[10100];//???????????¨????????°?????°

int main(){

	

	//stu[m] [0]?????? t[1]PC n[2]?????°?????? s

	while(1){

		vii stu[10100];

		int n,m;

		int r;

		cin >> n >> m;

		if(n==0&&m==0) break;

		cin >> r;

		rep(i,m){

			ln[i]=0;

			rep(j,1000){

				per[i][j]=0;

			}	

		}

		rep(i,r){

			int t,n,m,s;

			cin >> t >> n >> m >> s;

			m-=1;

			stu[m].pb(make_pair(t,s));

			ln[m]++;

 		}

 		rep(i,m){

 			int ms = 0;

 			int p = 0;

 			rep(j,ln[i]){

 				if(stu[i][j].se==1){



 					if(ms==0){

 						per[i][p++] = stu[i][j].fi;

 					}

 					ms++;

 				}else if(stu[i][j].se==0){

 					if(ms==1){

 						per[i][p++] = stu[i][j].fi;

 					}

 					ms--;

 				}

 			}

 			ln[i]=p;



 		}

 	// 	cout << "debug" << endl;

 	// 	rep(i,m){

		// 	rep(j,ln[i]){

		// 		cout << "j:"<<j<<""<< per[i][j] << " ";

		// 	}

		// 	cout << endl;

		// }

		// cout << endl;





		int q;

		cin >> q;

		rep(i,q){

			int ans =0;

			int ts,te,m;

			cin >> ts >> te >> m;

			m--;

			for(int j=0;j<ln[m]/2;j++){

				ans += max(0,min(te,per[m][j*2+1])-max(ts,per[m][j*2]));

			}

			// cout << "ans" << endl;

			cout << ans << endl;

		}



		



	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



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

#define REP(i,k,N) for(int i=k;i<(int)(N);i++)



using namespace std;

int main(){

    int N,M;

    while(cin >> N >> M,N) {

        int t[1000], n[1000], m[1000], s[1000];

        int r, q, begin, end, id;

        cin >> r;

        rep(i, r) cin >> t[i] >> n[i] >> m[i] >> s[i];

        cin >> q;

        rep(i, q) {

            cin >> begin >> end >> id;

            //ここまで入力



            int ans = 0,  pc= 0, B;

            rep(j, r) {

                if (m[j] != id)continue;

                if (s[j] == 1) {

                    //ログイン

                    pc++;

                    if (pc == 1) B = t[j];

                }else{

                    //ログアウト

                    pc--;

                    if (pc == 0 && begin <= t[j] && B <= end) {

                        ans += (min(end, t[j]) - max(begin, B));

                    }

                }

            }

            cout << ans << endl;

        }

    }

    return 0;

}


// 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;

}