main = getContents >>= putStr.unlines.map g.f.takeWhile (/="-").lines
    where f []       = []
          f (s:n:xs) = [s: (take (read n) xs)] ++ (f $drop (read n) xs)
          g (x:xs) = foldl h x $map read xs
          h y n = drop n y ++ take n y