object Main extends App {
  val line1 = io.StdIn.readLine.split(' ')
  val N = line1(0).toInt
  val Q = line1(1).toInt
  val S = io.StdIn.readLine

  for (i <- 0 until Q) {
    val lr = io.StdIn.readLine.split(' ')
    val sub = S.drop(lr(0).toInt - 1).dropRight(N - lr(1).toInt)
    println(sub.split("AC",-1).size - 1)
  }
}