loop do
  str = gets.chomp
  break if str == "-"
  count = gets.chomp.to_i
  ARGF.each.with_index(1) do |s, i|
    a = str.slice!(0, s.to_i)
    str += a
    break if (i == count)
  end
  puts str
end