while true
    cards = gets.chomp
    if cards == "-"
        exit
    end
    
    len = cards.length
    n = gets.to_i
    
    for i in 1..n
        m = gets.to_i
        cards = cards.slice(m, len - m) << cards.slice(0, m)
    end
    puts cards
end
