loop do
  cards = readline.chomp.chars
  break if cards.first == '-'
  times = readline.to_i
  hs = times.times.map { readline.to_i }.inject(:+)
  i = hs % cards.length
  a, b = cards[0, i], cards[i, cards.length]
  puts [b, a].flatten.join
end