main = interact $ unlines . map (itp1_9_b) . read' . lines
 where
  read' ("-":_) = []
  read' (str:n:xs) = (str, (map read . take (read n)) xs) : read' (drop (read n) xs)

itp1_9_b (str,hs) = foldr ($) str (map shuffle hs)
 where shuffle n str = let (bot,top) = splitAt n str in top ++ bot