import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  s <- getLine
  when (s /= "-") $ do
    m <- readLn
    hs <- replicateM m readLn
    putStrLn $ solve s hs
    main

solve :: String -> [Int] -> String
solve s hs = s1 ++ s0
 where
  h = sum hs `rem` length s
  (s0, s1) = splitAt h s

