import Control.Monad

main :: IO ()
main = do
    w <- getLine
    when (w /= "-") $ do
        m <- readLn
        n <- fmap ((`rem` length w) . sum) (replicateM m readLn)
        putStrLn $ drop n w ++ take n w
        main
