(* O(n + q) *)
open Array
let n, q, s = Scanf.scanf " %d %d %s" @@ fun a b c -> a, b, c
let lrs = init q @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let sums = make (n + 1) 0
let _ =
  String.iteri (fun i c -> sums.(i + 1) <- sums.(i) + if c = 'A' && i + 1 < n && s.[i + 1] = 'C' then 1 else 0) s;
  iter (fun (l, r) -> Printf.printf "%d\n" @@ sums.(r) - sums.(l)) lrs