#!/usr/bin/env ruby


result = []
while true
    cards = gets.chomp
    if cards == "-" then
        break
    end
    loopnumber = gets.to_i
    loopnumber.times do
        shufflenumber = gets.to_i
        temp = cards * 2
        cards = temp.slice(shufflenumber,cards.length)
    end
    result << cards
end
puts result

