import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val indicesSetNumber = sc.nextLine().split(" ")(1).toInt
    getAC(sc, indicesSetNumber.toInt)
  }

  def getAC(sc: Scanner, indicesSetNumber: Int) = {
    val targetLetters: String = sc.nextLine()

    @annotation.tailrec
    def go(n: Int): Unit = {
      if (n == 0) return
      else {
        val indices: Array[Int] = sc.nextLine().split(" ").map(i => i.toInt)
        val subset = targetLetters.slice(indices(0) - 1, indices(1))
        if (subset.length <= 1) println(0)
        else {
          var matchNumber = 0
          (subset.slice(0, subset.length()) zip subset.slice(1, subset.length() + 1)) map {
            case ('A', 'C') => matchNumber = matchNumber + 1
            case _ => 0
          }
          println(matchNumber)
          go(n - 1)
        }
      }
    }
    go(indicesSetNumber)
  }
}
