object Main {

  import java.util.Scanner
  import scala.collection.mutable.ArrayBuffer

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val (n, q) = (sc.nextInt(), sc.nextInt())
    val s = sc.next()
    debug(n, q, s.toSeq)

    val indexBuf = ArrayBuffer.empty[Int]
    for (i <- 0 until s.length - 1) {
      if (s(i) == 'A' && s(i + 1) == 'C') indexBuf += i
    }
    debug(indexBuf.toSeq)

    (1 to q).map(_ => (sc.nextInt(), sc.nextInt())).map { case (l, r) =>
      indexBuf.count(i => i >= l - 1 && i < r - 1)
    }.mkString("\n")
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}
