import scala.io.StdIn
import scala.language.implicitConversions

object Main extends App {
  val Array(n, q) = StdIn.readLine().split(" ").map(_.toInt)
  val s = StdIn.readLine()
  val lrs = for {
    _ <- 0 until q
  } yield {
    val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)

    (l, r)
  }

  lrs
    .map { case (l, r) =>
      s.substring(l - 1, r).countAC
    }
    .foreach(println)

  implicit def a(v: String): RichString = RichString(v)

  case class RichString(value: String) extends AnyVal {
    def countAC: Int = {
      (for {
        x <- 1 until value.length
      } yield if (value.charAt(x -1) == 'A' && value.charAt(x) == 'C') {
        1
      } else {
        0
      }).sum
    }
  }
}
