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()
let ranges = List.map (fun _ -> getIntPair()) [1..q]
List.map (fun (start, stop) -> cut s start stop |> countAC |> string) ranges
|> String.concat "\n"
|> printfn "%s"

