#include <iostream>
#include <algorithm>
using namespace std;

const int MINT = 540, MAXT = 1260;
const int T = MAXT - MINT;
const int N = 1000, M = 10000;

short records[M + 1][T + 1];

int main(){
	int n, m, r, q;
	while(cin >> n >> m, n){
		cin >> r;
		int s, e, t, a, b, ans = 0;
		for(int i = 0; i < m; ++i){
			fill(records[i], records[i] + T + 1, 0);
		}
		for(int i = 0; i < r; ++i){
			cin >> t >> a >> b >> s;
			if(s){
				++records[b][t - MINT];
			}
			else{
				--records[b][t - MINT];
			}
		}
		for(int i = 1; i <= m; ++i){
			for(int j = 0;j <= T;++j){
				records[i][j] += records[i][j - 1];
			}
		}
		cin >> q;
		for(int i = 0; i < q; ++i){
			cin >> a >> b >> m;
			ans = 0;
			a -= MINT;
			b -= MINT;
			for(int j = a;j < b; ++j){
				if(records[m][j]) ++ans;
			}
			cout << ans << endl;
		}
	}
	return 0;
}