import scala.io.StdIn._
object Main extends App {
  val Array(n, q) = readLine.split(" ").map(_.toInt)
  val s = readLine
  var ac: List[(Int, Int)] = List.empty
  for (i <- 1 until s.length) {
    if (s.substring(i - 1, i + 1) == "AC") {
      ac = (i, i + 1) :: ac
    }
  }
  (1 to q).foreach { _ =>
    val Array(l, r) = readLine.split(" ").map(_.toInt)
    println(ac.count { t =>
      l <= t._1 && t._2 <= r
    })
  }

}
