module ABC122.C

open System

let readPair () =
    Console.ReadLine().Split ' '
    |> Array.map int
    |> fun array -> array.[0], array.[1]

let rec count l r idx cnt slst =
    if l > idx then
        count l r (idx + 1) cnt (List.tail slst)
    elif idx > (r - 1) then
        cnt
    else
        match slst with
        | [] -> cnt
        | [x] -> cnt
        | 'A' :: ['C'] -> cnt + 1
        | 'A' :: 'C' :: tail -> count l r (idx + 2) (cnt + 1) tail
        | _ :: tail -> count l r (idx + 1) cnt tail

[<EntryPoint>]
let main argv =
    let (n, q) = readPair()
    let s = Console.ReadLine()
    for i in 1..q do
        let (l, r) = readPair()
        s
        |> Seq.toList
        |> count l r 1 0
        |> printfn "%d"
    0
