import Data.Array.IArray

main :: IO ()
main = do
  n : q : _ <- map read . words <$> getLine
  s <- getLine
  let
    ks = listArray (1, n) . countAC $ s
    f (l, r) = ks ! l - ks ! r
  lrs <- sequence . replicate q $ (unsafeListToPair . map read . words) <$> getLine
  mapM_ (print . f) lrs

countAC :: String -> [Int]
countAC = map snd . scanr step (False, 0)
  where
    step 'A' (True, k) = (False, succ k)
    step c (_, k) = (c == 'C', k)

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