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) = string.[start..stop]

let [_; inputLen] =
    let input = Console.ReadLine()
    input.Split(' ') |> Array.toList |> List.map (Int32.Parse)

let input = Console.ReadLine()

for _ in 1 .. inputLen do
    let [start; stop] =
        let input = Console.ReadLine()
        input.Split(' ') |> Array.toList |> List.map (Int32.Parse)
    let substr = cut input start stop    
    printfn "%i" <| getACCount substr
