open Printf
open Scanf

let (++) = Int64.add
let (--) = Int64.sub
let ( ** ) = Int64.mul
let (//) = Int64.div
let (%%) = Int64.rem
let landl = Int64.logand
let lorl = Int64.logor
let lnotl = Int64.lognot
let lxorl = Int64.logxor
let lsll = Int64.shift_left
let lsrl = Int64.shift_right_logical
let long = Int64.of_int
let succl = Int64.succ
let predl = Int64.pred

let read_int _ = scanf " %d " (fun x -> x)
let read_long _ = scanf " %Ld " (fun x -> x)
let read_str _ = scanf " %s " (fun x -> x)
let read_double _ = scanf " %f " (fun x -> x)
let read_pair _ = scanf " %d %d " (fun n q -> (n,q))

let explode s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []

let cnt s =
  let rec cnt' accum c prev = function
    | [] -> List.rev accum
    | 'C' :: rest when prev = 'A' -> cnt' (c+1 :: accum) (c+1) 'C' rest
    | b :: rest -> cnt' (c::accum) c b rest in
  let l = cnt' [0] 0 'B' (explode s) in
  Array.of_list l

let () =
  let n,q = read_pair () in
  let s = read_str () in
  let ctr = cnt s in
  let queries = Array.init q read_pair in
  Array.iter (fun (l,r) -> printf "%d\n" (ctr.(r) - ctr.(l))) queries
