import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, q) = in.readLine.split(" ").map(_.toInt)
  val s = in.readLine

  val table = Array.ofDim[Int](n)

  var acc = 0
  for(i <- 0 until n-1) {
    val ss = s.substring(i,i+2)
      table(i) = acc
    if(ss == "AC") {
      acc += 1
    }
  }
  table(n-1) = acc

  // debug(table.mkString(" "))
  val out = new java.io.PrintWriter(System.out)
  Iterator.continually(in.readLine)
    .take(q)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => {
      val l = e(0) - 1
      val r = e(1) - 1
      // debug(l,r)
      out.println(table(r) - table(l))
    })
  out.flush

  def debug(any:Any*):Unit = {
    if(this.getClass.toString == "class Main$") return
    println(any.mkString(" "))
  }
}