import Control.Monad

main = do
  [n, q] <- map read . words <$> getLine
  s <- getLine
  qs <- replicateM q $ fmap (map read . words) getLine :: IO [[Int]]
  mapM_ print $ map (solve s) qs

solve :: String -> [Int] -> Int
solve s [l, r] =
  f ss
  where
    ss = drop (l-1) . take r $ s
    f xs@[_, _] = if xs == "AC" then 1 else 0
    f (x:y:rest) = (if [x,y] == "AC" then 1 else 0) + f (y:rest)