object Main extends App {
    var get1 = readLine.split(" ")
    var wordMax = get1(0).toInt
    var loop = get1(1).toInt
    var words = readLine
    var i = 0
    var j = 0
    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-1)=='A' && words.charAt(j)=='C')
      sum += 1
    }
    println(sum)
    sum=0
  }
}