open System.IO
open System

let [| n; q; |] = stdin.ReadLine().Split() |> Array.map int
let s = stdin.ReadLine()
let lr = [| for _ in 1..q -> stdin.ReadLine().Split() |> Array.map int |]

let sw = new StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush <- false
Console.SetOut(sw)

[
    for [| lElem; rElem; |] in lr do
        let sub = s.Substring(lElem - 1, rElem - lElem + 1)
        let countAC total cand =
            match cand with
            |'A', 'C' -> total + 1
            | _ -> total 
        yield (sub.ToCharArray() |> Array.pairwise |> Array.fold countAC 0)]
|> List.iter stdout.WriteLine

stdout.Flush()
