import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, q = sc.nextInt()
    val s = sc.next().toCharArray
    
    val acs = new Array[Int](n)
    acs(0) = 0
    
    for (i <- s.indices) {
      if (i != 0) {
        if (s(i - 1) == 'A' && s(i) == 'C') {
          acs(i) = acs(i - 1) + 1
        } else {
          acs(i) = acs(i - 1)
        }
      }
    }
    
    for (i <- 0 until q) {
      val l, r = sc.nextInt()
      println(acs(r - 1) - acs(l - 1))
    }
    
  }
  
  def printArray[T](arr: Array[T]): Unit = {
    for (i <- arr.indices) {
      print(s"${arr(i)} ")
    }
    println()
  }
}