object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, Q = sc.nextInt()
  val S = sc.next().toCharArray
  val indecies = (1 until N).scanLeft(0) { (acc, i) =>
    if (S(i - 1) == 'A' && S(i) == 'C') acc + 1 else acc
  }.toArray
  List.fill(Q)(sc.nextInt() -> sc.nextInt()).map { case (l, r) =>
    indecies(r - 1) - indecies(l - 1)
  }.foreach(println)
}
