import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Array.IArray

main :: IO ()
main = do
    _ <- getLine
    s <- BS.unpack <$> BS.getLine
    lr <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents
    mapM_ print $ solve s lr

part :: Int -> Int -> [a] -> [a]
part i n = take n . drop i

solve :: String -> [(Int,Int)] -> [Int]
solve s = map (\(l,r) -> arr!(r-1) - arr!(l-1))
  where
    n = length s
    arr = listArray (0,n+1) (0:map f [1..n]) :: Array Int Int
    f i = arr!(i-1) + if part (i-1) 2 s == "AC" then 1 else 0
