#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999



int main(){
    int n,m;
    while(cin>>n>>m&&n&&m){
        static int data[10001][1261-500];//500テ」ツつ津ィツカツウテ」ツ??
        memset(data,0,sizeof(data));
        int r;
        cin>>r;
        rep(i,r){
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            if(d!=0){
                data[c][a-500]++;
            }else{
                data[c][a-500]--;
            }
        }
        rep(i,m+1){
            rep(j,1261-500-1){
                data[i][j+1]+=data[i][j];
//                cout<<data[i][j];
            }
//            cout<<endl;
        }
        int q;
        cin>>q;
        rep(i,q){
            int s,e,v;
            cin>>s>>e>>v;
            int sum=0;
            for(int j=s-500;j<e-500;j++)sum+=!!data[v][j];
            cout<<sum<<endl;
        }
    }
    
}