import Control.Applicative
main = do xs <- lines <$> getContents
          putStr . unlines $ solve xs

solve :: [String] -> [String]
solve ("-":_)  = [] 
solve (s:m:xs) = shuffles s hs : solve rest
                    where (hs',rest) = splitAt (read m) xs
                          hs = map read hs'

shuffles :: String -> [Int] -> String
shuffles s hs = foldr shuffle s hs

shuffle :: Int -> String -> String
shuffle h s = af ++ bf
    where (bf,af) = splitAt h s