import scala.io.StdIn

object Main extends App {
  val Array(n, q) = StdIn.readLine().split(" ").map(_.toInt)
  val s = StdIn.readLine()
  val lrs = Stream.continually(StdIn.readLine()).takeWhile(_ != null)
      .map { lr =>
        val Array(l, r) = lr.split(" ").map(_.toInt)
        
        (l, r)
      }
  
  lrs
    .map { case (l, r) =>
      s.substring(l, r).split("AC").length - 1
    }
    .foreach(println)
}
