#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

struct Log{
  int t;
  int s;
};

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n==0){
      return 0;
    }
    int r,q;
    cin >> r;
    vector<list<struct Log>> gakusei(m+1,list<struct Log>());
    int a,b,c,d;
    for(int i=0;i<r;i++){
      cin >> a >> b >> c >> d;
      gakusei[c].push_back({a,d});
    }
    int ts,te,id;
    int ans=0,count=0;
    cin >> q;
    int begin,end;
    for(int i=0;i<q;i++){
      cin >> ts >> te >> id;
      ans=count=0;
      for(auto itr=gakusei[id].begin();itr!=gakusei[id].end();itr++){
        if((*itr).s==1){
          count++;
          if(count==1){
            begin=max((*itr).t,ts);
          }
        }else{
          count--;
          if(count==0){
            end=min((*itr).t,te);
            ans+=(end>begin?end-begin:0);
          }
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}

