[<AutoOpen>]
module Program

open System

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

let prefix n (a : char []) =
    let b = Array.init n (fun _ -> 0)
    let rec aux c i =
        if i >= n then
            ()
        elif a.[i] = 'A' && a.[i+1] = 'C' then
            b.[i] <- c
            b.[i+1] <- c + 1
            aux (c + 1) (i + 2)
        else
            b.[i] <- c
            aux c (i + 1)
    aux 0 0
    b

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