loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    r = gets.to_i
    log = r.times.map{gets.split.map(&:to_i)}
    q = gets.to_i
    fr = q.times.map{gets.split.map(&:to_i)}
    c = Array.new(m).map{Array.new(1260,0)}
    log.each do |l|
        c[l[2]-1][l[0]] += l[3] == 1 ? 1 : -1
    end
    fr.each do |f|
        u = Marshal.load(Marshal.dump(c[f[2]-1]))
        u.each_with_index do |d,j|
            next if j == 0
            u[j] += u[j-1]
        end
        p u[f[0]...f[1]].count{|d| d > 0}
    end
end