import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val arr = readLine.split(" ").map(_.toInt).toBuffer
  val n = arr(0)
  val q = arr(1)
  val s = readLine
  var i = 0
 
  while (i < q) {
    val splits = readLine.split(" ").map(_.toInt).toBuffer
    val subs = s substring(splits(0) - 1, splits(1))
    println(countAC(subs))
    i += 1
  }
  
  def countAC(s: String): Int = {
    s.sliding(2).count(_ == "AC")
  }
}