import scala.io.StdIn

object Main extends App {
  val Array(n, q) = StdIn.readLine().split(" ").map(_.toInt)
  val s = StdIn.readLine()
  val lrs = for {
    _ <- 0 until q
  } yield {
    val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)

    (l, r)
  }

  lrs
    .map { case (l, r) =>
      "AC".r.findAllIn(s.substring(l - 1, r)).size
    }
    .foreach(println)
}
