import Data.Char

main = interact $ unlines . map unreliable_message . groupAt 2 . tail . lines

unreliable_message [ms,str] = foldr relay_rev str ms
 where
  relay_rev 'J' s = last s : init s
  relay_rev 'C' s = tail s ++ [head s]
  relay_rev 'E' s = if odd (length s) then xs2 ++ [x] ++ xs1 else xxs ++ xs1
   where (xs1,xxs@(x:xs2)) = splitAt (div (length s) 2) s
  relay_rev 'A' s = reverse s
  relay_rev 'P' s = map (\c -> if c=='0' then '9' else if isDigit c then pred c else c) s
  relay_rev 'M' s = map (\c -> if c=='9' then '0' else if isDigit c then succ c else c) s

groupAt n xs
 | null xs = []
 | otherwise = take n xs : groupAt n (drop n xs)