#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int use[10004][1300]; 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while(cin>>N>>M,N||M) {
    CLR(use);
    int r; cin >> r;
    FOR(i,0,r) {
      int t, n , m , s;
      cin >> t >> n >> m >> s;
      if(s == 1) {
        use[m][t]++;
      } else {
        use[m][t]--;
      }
    }
    FOR(i,1,M+1) {
      FOR(j,0,1299) {
        use[i][j+1] += use[i][j];
      }
    }
    int q; cin >> q;
    FOR(i,0,q) {
      int ts, te, m;
      cin >> ts >> te >> m;
      int ans = 0;
      FOR(j,ts,te) {
        if(use[m][j] > 0) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}