require 'set'

class ExpectedValue
  def initialize grid, roulettes, events
    @grid = grid
    @roulettes = roulettes
    @events = events
    @dp = Array.new(grid+1){Array.new(grid+1,0)}
    @stack = []
    @visited = Set.new()
  end

  def exec
    @stack << [0,0]
    while order = @stack.shift()
      repeater(order[0], order[1])
    end
    answer = @dp[@grid].each_with_index.inject(0) do |sum, (score, times)|
      sum + score / (@roulettes.length ** times).to_f
    end
    puts answer.to_i
  end

  def repeater position, times
    unless @visited.include?([position, times])
      @roulettes.each do |roulette|
        score = @dp[position][times]
        destination = position + roulette
        if ! (destination >= @grid) && event = @events[destination]
          case event[:type]
          when 1
            destination += event[:value]
          when 2
            score += event[:value]
          when 3
            score -= event[:value]
          end
        end
        score = 0 if score < 0
        if destination >= @grid
          @dp[@grid][times+1] += score
        else
          @dp[destination][times+1] += score
          @stack << [destination,times+1]
        end
        @visited << [position, times]
      end
    end
  end
end

until [0,0,0] == one = gets.split(" ").map(&:to_i)
  roulette,grid,z = one
  roulettes = gets.split(" ").map(&:to_i)
  events = {}
  z.times do
    n,e,a = gets.split(" ").map(&:to_i)
    events[n] = {type: e, value: a}
  end
  expected_value = ExpectedValue.new(grid,roulettes,events)
  expected_value.exec()
end