import Data.Bool (bool)

main :: IO ()
main = do
  n : q : _ <- map read . words <$> getLine
  s <- getLine
  let
    is = posAC s
    f (l, r) = length . filter ((&&) <$> (l <=) <*> (< r)) $ is
  lrs <- map (unsafeListToPair . map read . words) . lines <$> getLine
  mapM_ (print . f) lrs

posAC :: String -> [Int]
posAC = \s -> snd . snd $ foldr step (False, (length s, [])) s
  where
    step 'A' (b, (i, is)) = (False, (pred i, bool is (i : is) b))
    step c (_, (i, is)) = (c == 'C', (pred i, is))

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair (x : y : _) = (x, y)
unsafeListToPair _ = undefined
