open System

let getCounts (str: string) =
    let rec inner acc = function
    | 'A' :: 'C' :: tl ->
        let added = acc + 1
        Array.append [|acc; added|] (inner added tl)
    | _ :: tl ->
        Array.append [|acc|] (inner acc tl)
    | _ -> [||]    
    inner 0 <| Seq.toList str    

let getCount (counts: int[]) (start: int) (stop: int) =
    counts.[stop - 1] - counts.[start - 1]

let getIntPair() =
    let input = Console.ReadLine().Split(' ') |> Array.map int
    input.[0], input.[1]

let _, q = getIntPair()
let s = Console.ReadLine()
let counts = getCounts s
for _ in 1..q do 
    let start, stop = getIntPair()
    getCount counts start stop |> printfn "%i"
