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


  line = Hash.new
  m.times do |i|
    line[i+1] = Array.new
  end


  login = Hash.new
  r = gets.chomp.to_i
  r.times do
    t, pc, st, s = gets.chomp.split.map &:to_i
    if ( s == 1 )
      login[[pc, st]] = t

    else
      b = login[[pc, st]]
      e = t

      rm = Array.new
#      puts "-------- #{st} =|#{b} #{e}|"
      line[st].each_with_index do |l, i|
#        puts "#{b} ~ #{e} || #{i} => #{l[0]} ~ #{l[1]}"

        if b < l[0] && e >= l[0]
          l[0] = b
        end

        if ( b >= l[0] && b <= l[1] ) || ( e > l[0] && e <= l[0] )
          if ( b >= l[0] && b <= l[1] )
            b = l[0]
          end

          if ( l[1] > e )
            e = l[1]
          end
          rm << i
        end
      end
      rm.each do |d|
        line[st].delete_at d
      end
      line[st] << [b, e]
      login.delete [pc, st]
    end

#p line

  end

  

  q = gets.chomp.to_i
  q.times do
    ts, te, st = gets.chomp.split.map &:to_i
    minute = 0
    line[st].each do |l|
#      puts "-> #{ts} ~ #{te} L=|#{l[0]} ~ #{l[1]}|="
      minute +=
        if l[0] > ts && l[1] < te
          l[1] - l[0]
        elsif l[0] <= ts && l[1] >= te
          te - ts
        elsif l[0] >= ts && l[1] >= te
          te - l[0]
        elsif l[0] <= ts && l[1] >= ts && l[1] <= te
          l[1] - ts
        else
          0
        end
    end

#    puts "#========> #{minute}"
    puts minute

  end
end