def f(i, m)
    c = $cache[[i, m]]
    return c if c
    return m if i >= $y
    e = 0
    $roulette.each do |v|
        if $event[i + v]
            if $event[i + v][0] == 1
                e += f(i + v + $event[i + v][1], m) / $roulette.size.to_f
            elsif $event[i + v][0] == 2
                e += f(i + v, m + $event[i + v][1]) / $roulette.size.to_f
            else
                e += f(i + v, [m - $event[i + v][1], 0].max) / $roulette.size.to_f
            end
        else
            e += f(i + v, m) / $roulette.size.to_f
        end
    end
    $cache[[i, m]] = e
end

loop do
    x, $y, z = gets.split.map(&:to_i)
    break if x == 0
    $roulette = gets.split.map(&:to_i)
    $event = {}
    z.times do
        n, e, a = gets.split.map(&:to_i)
        $event[n] = [e, a]
    end
    $cache = {}
    p f(0, 0).to_i
end

