let () = Scanf.scanf "%d %d\n%s\n" @@ fun n q s ->
  let acc = Array.make (n + 1) 0 in
  for i = 1 to n - 1 do
    acc.(i + 1) <- acc.(i) + (if s.[i - 1] = 'A' && s.[i] = 'C' then 1 else 0)
  done;
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d\n" @@ fun l r ->
      Printf.printf "%d\n" @@ acc.(r) - acc.(l)
  done
