module ABC122.C

open System

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

let rec toTs prev slst res =
    match slst with
    | [] -> res
    | [x] -> res @ [prev]
    | 'A' :: 'C' :: tail ->
        let crt = prev + 1
        toTs crt tail (res @ [crt; crt])
    | _ :: tail -> toTs prev tail (res @ [prev])

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