let query ac = 
  Scanf.scanf " %d %d" (fun l' r' -> (
    let l = l' - 1 in
    let r = r' - 1 in
    Printf.printf "%d\n" (ac.(r) - ac.(l))
  ))
;;

let () = Scanf.scanf "%d %d\n%s" (fun n q s -> (
  let ac = Array.init (n + 1) (fun i -> if i = n || i = 0 || s.[i - 1] <> 'A' || s.[i] <> 'C' then 0 else 1) in (
    Array.iteri (fun i e -> if i > 0 then ac.(i) <- ac.(i - 1) + e) ac;
    for i = 1 to q do
      query ac
    done
  )
))