import Control.Monad (forM)

shuffle :: Int -> String -> String
shuffle n cards = shuffle' n (length cards) (cards++cards)
  where
      shuffle' :: Int -> Int -> String -> String
      shuffle' 0 0 _      = []
      shuffle' 0 m (x:xs) = x:(shuffle' 0 (m-1) xs)
      shuffle' n m (x:xs) = shuffle' (n - 1) m xs

main :: IO ()
main = do
    cards <- getLine
    if cards == "-" then return ()
    else do
        m <- getLine >>= return . (\n -> read n :: Int)
        n <- (forM [1..m] $ \_ -> getLine) >>= return . map (\n -> read n :: Int)
        putStrLn $ shuffles n cards
        main
  where
      shuffles :: [Int] -> String -> String
      shuffles []     cards = cards
      shuffles (x:xs) cards = shuffles xs $ shuffle x cards
