#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	while (N) {
		cin >> K;
		vector<vector<bool>>flag(M, vector<bool>(721));
		vector<queue<int>>Q(N);
		for (int i = 0; i < K; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a -= 540;
			b--;
			c--;
			if (d) {
				Q[b].push(a);
			}
			else {
				for (int j = Q[b].front(); j < a; j++) {
					flag[c][j] = true;
				}
				Q[b].pop();
			}
		}
		cin >> K;
		for (int i = 0; i < K; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a -= 540;
			b -= 540;
			c--;
			int ans = 0;
			for (int j = a; j < b; j++) {
				ans += flag[c][j];
			}
			cout << ans << endl;
		}
		cin >> N >> M;
	}
	return 0;
}