(* 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 _ = Scanf.scanf " %d %d %s" @@ fun n q s ->
  let left = get_left_info s in
  for i = 1 to q do
    Scanf.scanf " %d %d" @@ fun l r ->
      Printf.printf "%d\n" @@ left.(r) - left.(l) (* l = l + |"AC"| - 1 - 1 *)
  done