import Data.Functor( (<$>))
import Control.Monad( replicateM, filterM, (<=<))
import Data.List( foldl', unfoldr)

main = do
    rawOrders <- filterM (return . ("-"/=)) =<< lines <$> getContents
    let
	interprete list = unfoldr pack list
	  where
	    pack [] = Nothing
	    pack (str:num:shu)
	      = let
		    shuffleSize = read num
		    (shuffles, remain) = splitAt shuffleSize shu
		in
		    Just ((str,shuffles), remain)

	processPerOrder (orgStr, shuffles)
	  = let
		shuffle str n = b++a where (a,b) = splitAt (read n) str
	    in
		foldl' shuffle orgStr shuffles

    (putStrLn . processPerOrder) `mapM_` interprete rawOrders

