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.countAC(l - 1, r)
    }
    .foreach(println)

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

  case class RichString(value: String) extends AnyVal {
    def countAC(from: Int, to: Int): Int = {
      (from + 1 until to)
        .foldLeft(0)((sum, x) => if (value.charAt(x -1) == 'A' && value.charAt(x) == 'C') {
          sum + 1
        } else {
          sum
        })
    }
  }
}
