import Control.Monad
main = do
  [n,q] <- map read . words <$> getLine
  s <- getLine
  lr <- replicateM q $ map read . words <$> getLine
  let a = map (f s) lr
  putStrLn $ unlines $ map (g 0) a
f y zs = drop (head zs - 1) (take (last zs) y)
g c bs
  | length bs <= 1 = show c
  | take 2 bs == "AC" = g (c+1) (drop 2 bs)
  | otherwise = g c (tail bs)