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

posAC :: Int -> String -> [Int]
posAC = \n -> snd . snd . foldr step (False, (n, []))
  where
    step 'A' (True, (i, is)) = (False, (pred i, i : is))
    step c (_, (i, is)) = (c == 'C', (pred i, is))

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