while 1:

	N,M = list(map(int,input().split()))

	if N == 0: break

	T = [[0]*1261 for i in range(N)]

	r = eval(input())

	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])

	for i in range(0,r,2):

		t1,n,m,s = tnms[i]

		t2,n,m,s = tnms[i+1]

		T[n-1][t1:t2] = [m for j in range(t1,t2)]

	for i in range(eval(input())):

		ts,te,m = list(map(int,input().split()))

		print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))

	
while 1:

	N,M = list(map(int,input().split()))

	if N == 0: break

	T = [[0]*1261 for i in range(M)]

	r = eval(input())

	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])

	for i in range(0,r,2):

		t1,n,m,s = tnms[i]

		t2,n,m,s = tnms[i+1]

		T[m-1][t1:t2] = [1 for j in range(t1,t2)]

	for i in range(eval(input())):

		ts,te,m = list(map(int,input().split()))

		print(sum(T[m-1][ts:te]))
while 1:
    N, M = list(map(int, input().split()))
    if N == 0:
        break
    T = [[0] * 1261 for i in range(N)]
    r = eval(input())
    tnms = sorted(
        [list(map(int, input().split())) for i in range(r)], key=lambda x: x[1]
    )
    for i in range(0, r, 2):
        t1, n, m, s = tnms[i]
        t2, n, m, s = tnms[i + 1]
        T[n - 1][t1:t2] = [m for j in range(t1, t2)]
    for i in range(eval(input())):
        ts, te, m = list(map(int, input().split()))
        print(
            sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts, te))
        )

while 1:
    N, M = list(map(int, input().split()))
    if N == 0:
        break
    T = [[0] * 1261 for i in range(M)]
    r = eval(input())
    tnms = sorted(
        [list(map(int, input().split())) for i in range(r)], key=lambda x: x[1]
    )
    for i in range(0, r, 2):
        t1, n, m, s = tnms[i]
        t2, n, m, s = tnms[i + 1]
        T[m - 1][t1:t2] = [1 for j in range(t1, t2)]
    for i in range(eval(input())):
        ts, te, m = list(map(int, input().split()))
        print(sum(T[m - 1][ts:te]))

-    T = [[0] * 1261 for i in range(N)] +    T = [[0] * 1261 for i in range(M)] -        T[n - 1][t1:t2] = [m for j in range(t1, t2)] +        T[m - 1][t1:t2] = [1 for j in range(t1, t2)] -        print( -            sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts, te)) -        ) +        print(sum(T[m - 1][ts:te]))