(* O(n) *)
let rec fold_btw f a i n = if i >= n then a else fold_btw f (f a i) (i + 1) n
let fold_int f a n = fold_btw f a 0 n

(* O(|s|) *)
let get_left_info s =
  let n = String.length s in
  let left = Array.make (n + 1) 0 in
  for i = 1 to n - 1 do
    if s.[i - 1] = 'A' && s.[i] = 'C' then
      left.(i + 1) <- left.(i) + 1
    else
      left.(i + 1) <- left.(i)
  done;
  left

(* O(max {n, q}) *)
let solve n q s lrs =
  let left = get_left_info s in
  List.iter
    (fun (l, r) ->
      let l = l - 1 in
      let count = left.(r) - left.(l + 1) in (* l + 1 = l + |"AC"| - 1 *)
      string_of_int count |> print_endline)
    lrs

let _ = Scanf.scanf " %d %d %s" (fun n q s ->
  fold_int
    (fun acc _ -> Scanf.scanf " %d %d" (fun l r ->
      (l, r) :: acc))
    []
    q |> List.rev |> solve n q s)