def shuffle_cards(cards, num_of_cards)
  str =  cards[num_of_cards..-1] + cards[0..(num_of_cards-1)]
  return str
end

loop do
  cards = gets.chomp
  break if cards == "-" 
  num_of_shuffling = gets.chomp.to_i
  shuffle_num_of_cards = []
  num_of_shuffling.times { shuffle_num_of_cards.push(gets.chomp.to_i) }

  shuffle_num_of_cards.each do |i|
    cards = shuffle_cards(cards, i)
  end
  puts cards
end