open System

let countAC (str: string) =
    str.Split([|"AC"|], StringSplitOptions.None) 
    |> Array.length 
    |> (fun n -> n - 1)

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

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

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