import Control.Monad
import Control.Applicative
import Data.List

solve :: [String] -> [String]
solve [] = []
solve (ini:m:ls) =
    let (ns, ns') = splitAt (read m) ls in
    (foldl' shuffle ini $ map read ns) : solve ns'
    where
    shuffle :: String -> Int -> String
    shuffle s n =
        let (a,b) = splitAt n s in
        b ++ a

main =
    mapM_ putStrLn =<< solve . takeWhile (/= "-") . lines <$> getContents