import scala.io.StdIn._

object Main extends App {

  val Array(n,q) = readLine().split(" ").map(_.toInt)
  val s = readLine()
  val lr = Array.fill(q)(readLine().split(" ").map(_.toInt -1))

  def solve() = {
    val cSum = Array.fill(n)(0)
    for(i <- 0 until n) {
      if(i == 0) cSum(i) = 0
      else if(s(i-1) == 'A' && s(i) == 'C') cSum(i) = cSum(i-1) + 1
      else cSum(i) = cSum(i-1)
    }
    lr.map{ list =>
      cSum(list(1)) - cSum(list(0))
    }.mkString("\n")
  }
  println(solve())

}

