open System

let getACCount string =
    let rec inner acc = function 
    | 'A' :: 'C' :: tl -> inner (acc + 1) tl
    | _ :: tl -> inner acc tl
    | [] -> acc

    inner 0 <| Seq.toList string

let cut (string: string) (start: int) (stop: int) = 
    let (startIdx, stopIdx) = (start - 1, stop - 1)
    string.[startIdx..stopIdx]

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

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