let solve s n =
  let t = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    t.(i+1) <- if (String.sub s i 2) = "AC" then t.(i) + 1 else t.(i)
  done;
  fun (i, j) -> t.(j-1) - t.(i-1)

let _ =
  let n, q = Scanf.scanf "%d %d\n" (fun n q -> n, q) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  let queries = ref [] in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d\n" (fun l r -> queries := (l, r)::!queries)
  done;
  let solver = solve s n in
  List.fold_left (fun acc query -> (solver query)::acc) [] !queries
  |> List.iter (fun n -> print_int n; print_endline "")