loop {
	pc_num, student_num = gets.split.map &:to_i
	break if pc_num == 0

	event = (1..student_num).map { [] }

	r = gets.to_i
	r.times{
		t, n, m, s = gets.split.map &:to_i
		event[m-1] << [t, 2*s-1]
	}

	q = gets.to_i
	q.times{
		ts, te, m = gets.split.map &:to_i
		queue = event[m-1].dup

		i = queue.index{|t, s| ts < t} || queue.size
		queue.insert(i, [ts, 0])

		i = queue.index{|t, s| te < t} || queue.size
		queue.insert(i, [te, 0])

		c = 0
		sum = 0
		prev_t = 0
		check = false
		queue.each{|t, s|
			if check && c > 0
				sum += t - prev_t
			end
			check = !check if s == 0
			c += s
			prev_t = t
		}
		p sum
	}
}