open System

let getACCount string =
    let rec inner = function 
    | 'A' :: 'C' :: tl -> 1 + (inner tl)
    | _ :: tl -> 0 + inner tl
    | [] -> 0

    inner <| Seq.toList string

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

let getTwoInt() =
    let input = Console.ReadLine()
    match input.Split(' ') |> Array.toList |> List.map (Int32.Parse) with
    | [fst; sec] -> (fst, sec)
    | _ -> failwith "Undefined"

let (_, inputLen) = getTwoInt()

let input = Console.ReadLine()

for _ in 1 .. inputLen do
    let (start, stop) = getTwoInt()
    let substr = cut input start stop    
    printfn "%i" <| getACCount substr
