object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, Q = sc.nextInt
    val S = sc.next
    val results = new Array[Int](Q)
    for (i <- 0 until Q) {
      val l = sc.nextInt
      val r = sc.nextInt
      val substr = S.substring(l - 1, r)
      results(i) = substr.sliding(2).count("AC".==)
    }

    results.foreach(println)
  }
}