open System

let getACIndexes (str: string) =
    let rec inner cnt = function 
    | 'A' :: 'C' :: tl -> cnt :: (inner <| cnt + 2) tl
    | _ :: tl -> inner (cnt + 1) tl
    | [] -> []

    inner 1 <| Seq.toList str

let getACCount (indexes: int list) (start: int) (stop: int) =
    List.filter (fun n -> start <= n && n <= stop) indexes
    |> List.length

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

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