main = interact $ unlines . map kings_inspection . read' . lines
 where
  read' ("0":_) = []
  read' (_:k:s:xs') = (map read (words k), s) : read' xs'

kings_inspection (ks,str) = zipWith (\c n -> head . drop n . dropWhile (/=c) $alpha) str (cycle ks)
 where alpha = cycle (['Z','Y'..'A'] ++ ['z','y'..'a'])