import           Control.Monad
import           Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as V

main = do
  [_, q] <- map read.words <$> getLine
  s <- getLine
  let memo = V.fromList $ f (0::Int) s
      f n []           = [n]
      f n ('A':'C':cs) = n:n:f (n+1) cs
      f n (c:cs)       = n:f n cs
      solve 0 = return ()
      solve q = do
        [l, r] <- map read.words <$> getLine
        print (memo!r - memo!l)
        solve (q-1)
  solve q
