import Data.Char
import Control.Monad
main = do
  n <- getLine
  if n == "-" then return ()
  else do
    m <- readLn :: IO Int
    h <- replicateM m $ (readLn :: IO Int)
    putStrLn $ foldl f n h
    main
    
f n h = take (length n) $ drop h $ cycle n
