import Control.Monad
main = do
  [_,q] <- map read . words <$> getLine
  s <- getLine
  lrs <- replicateM q (map read . words <$> getLine) :: IO [[Int]]
  mapM_ (\[l,r] -> print $ getLR l r (ac 0 s)) lrs
  

ac :: Int -> String -> [Int] 
ac acc [] = []
ac acc [_] =  [acc]
ac acc (a:c:s)
  | [a,c] == "AC" = acc : (acc+1) : ac (acc+1) (s)
  | otherwise     = acc : ac acc (c:s)
  
getLR :: Int -> Int -> [Int] -> Int
getLR l r acs = (acs !! (r-1)) - (acs !! (l-1))