let solver s n _ =
  let memo = Array.make_matrix n n None in
  fun (i, j) ->
  match memo.(i - 1).(j - 1) with
  | Some n -> n
  | None ->
     let i, j = (i - 1), (j - 1) in
     let flag = ref false in
     let ct = ref 0 in
     for k = i to j do
       if (not !flag) && (String.get s k) = 'A' then flag := true
       else if !flag && (String.get s k) = 'C' then (ct := !ct + 1; flag := false)
       else flag := false
     done;
     memo.(i).(j) <- Some !ct;
     !ct

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 = solver s n q in
  List.fold_left (fun acc query -> (solver query)::acc) [] !queries
  |> List.iter (fun n -> print_int n; print_endline "")