import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val arr = readLine.split(" ").map(_.toInt).toBuffer
  val n = arr(0)
  val q = arr(1)
  val s = readLine.toIterator
  var i = 1
  var j = 0
  
  val startList = ArrayBuffer.empty[Int]
 
  while (s.hasNext) {
    val l = s.next()
    if (l.toString == "A") {
      if (s.next().toString == "C") {
        startList += i
        i += 1
      }
    }
    i += 1
  }
    
  while (j < q) {
    val lr = readLine.split(" ").map(_.toInt).toBuffer
    val l = lr(0)
    val r = lr(1)
    var count = 0
    var k = 0
    
    while(k < startList.size) {
      val start = startList(k).toInt
      if ((start >= l) && (start < r)) {
        count += 1
      }
      k += 1
    }
    
    println(count)
    j += 1
  }
}	