import scala.io.StdIn._
object Main extends App {
  val Array(n, q) = readLine.split(" ").map(_.toInt)
  val s = readLine
  var ac = new Array[Int](s.size)
  for (i <- 1 until s.length) {
    ac(i) =
      if (s(i - 1) == 'A' && s(i) == 'C') ac(i - 1) + 1
      else ac(i - 1)
  }
  (1 to q).foreach { _ =>
    val Array(l, r) = readLine.split(" ").map(_.toInt)
    println(ac(r-1) - ac(l - 1))
  }

}
