### constant

S_LOGIN =  1
S_LOGOUT = 0

### main

loop do
  n, m = gets.split.map(&:to_i)
  break if (n | m) == 0

  r = gets.to_i

  sts = m.times.map{[]}
  stpcs = m.times.map{0}

  r.times do
    t, pn, sm, s = gets.split.map(&:to_i)
    pn -= 1
    sm -= 1

    if s == S_LOGIN
      sts[sm] << [t, S_LOGIN] if stpcs[sm] == 0
      stpcs[sm] += 1
    else
      stpcs[sm] -= 1
      sts[sm] << [t, S_LOGOUT] if stpcs[sm] == 0
    end
  end
  #p sts
  #p stpcs

  q = gets.to_i

  q.times do
    ts, te, sm = gets.split.map(&:to_i)
    sm -= 1
    #p [ts, te, sm]

    total = 0
    t_in = nil

    sts[sm].each do |t, s|
      if s == S_LOGIN
        t_in = t
      else
        ts0 = (t_in > ts) ? t_in : ts
        te0 = (t < te) ? t : te
        total += te0 - ts0 if ts0 <= te0
        t_in = nil
      end
    end

    puts total
  end
end