import Control.Monad

main :: IO ()
main = do
  s <- getLine

  when (s /= "-") $ do
    m <- readLn
    hs <- replicateM m readLn
    putStrLn $ foldl (\acc h -> rotate h acc) s hs
    main

rotate :: Int -> String -> String
rotate n xs = drop n xs ++ take n xs