while str = gets.chomp do
  break if str == "-"
  arr = str.split("")
  n = gets.to_i
  n.times{
    h = gets.to_i
    h.times{
      s = arr.pop
      arr.push(s)
    }
  }
  printf "%s\n", arr.join("")
end