object Main extends App {
var get1 = readLine.split(" ")
var wordMax = get1(0).toInt
var loop = get1(1).toInt
var word = 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' && words.charAt(j-1)=='A')
//      	sum += 1
//    }
	var  words=word.slice(loopget(0).toInt-1,loopget(1).toInt)
//  sum = words.size - words.replaceAll("AC","").size
    println((words.size - words.replaceAll("AC","").size)/2)
//    println(sum)
//    sum=0
  }
}