[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let countAC ary =
    let xs = Array.toList ary
    let rec aux c = function
        | [] -> c
        | 'A' :: 'C' :: xs -> aux (c + 1) xs
        | _ :: xs -> aux c xs
    aux 0 xs

[<EntryPoint>]
let main _ =
    let [_;q] = reads int
    let ss = (read id).ToCharArray()
    let lrs = List.map (fun _ -> reads int |> fun [l;r] -> (l, r)) [1..q]
    List.iter (fun (l, r) -> countAC ss.[l-1..r-1] |> printfn "%i") lrs
    0