Scanf.scanf "%d %d" (fun n q ->
    Scanf.scanf " %s" (fun s ->
        let a = Array.make n 0 in
        let rec loop i prev cur =
            if i < n then (
                let cur = if prev = 'A' && s.[i] = 'C' then cur + 1 else cur in
                a.(i) <- cur;
                loop (i + 1) s.[i] cur
            )
        in
        loop 1 s.[0] 0;

        for i = 1 to q do
            Scanf.scanf " %d %d" (fun l r ->
                Printf.printf "%d\n" @@
                    if l = 1 then a.(r - 1)
                             else a.(r - 1) - a.(l - 1)
            )
        done
    )
)