import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  inputs <- takeWhile (/= "-") . lines <$> getContents
  putStrLn $ unlines $ sovle inputs
  where
    sovle []               = []
    sovle (cards:num:opts) = [foldl shuffle cards (map read (take (read num) opts))] ++ sovle (drop (read num) opts)
    shuffle card pos = (drop pos card) ++ (take pos card)

