object Main extends App {
var get1 = readLine.split(" ")
var loop = get1(1).toInt
var word = readLine
var count : Array[Int] = new Array(word.size)
	for(i <- 1 to word.size - 1) {
    	count(i) = 
     		if(word(i-1)=='A' && word(i)=='C') count(i - 1) + 1 
    		else count(i - 1)
    }
  	for(i <- 0 to loop - 1) {
      var position = readLine.split(" ")
    	println(count(position(1).toInt - 1) - count(position(0).toInt - 1))
    }
}