[<AutoOpen>]
module Program

open System

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

let count l r n (xs : char []) =
    let rec aux c i =
        if i >= r || i >= n then
            c
        elif xs.[i] = 'A' && xs.[i+1] = 'C' then
            aux (c + 1) (i + 2)
        else
            aux c (i + 1)
    aux 0 l

[<EntryPoint>]
let main _ =
    let [n;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) -> count (l - 1) (r - 1) n ss |> printfn "%i") lrs
    0