object Main extends App {
var get1 = readLine.split(" ")
var wordMax = get1(0).toInt
var loop = get1(1).toInt
var words = readLine
var sum = 0

for(i <- 0 to loop - 1) {
  var loopget = readLine.split(" ")
  for(j <- loopget(0).toInt to loopget(1).toInt-1) {
    if(words.charAt(j)=='C')
    	if(words.charAt(j-1)=='A')
      		sum += 1
    }
    println(sum)
    sum=0
  }
}