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

    var count = 0
    val sums = for (i <- 0 until N) yield {
      if (i == 0) {
        0
      } else if (S(i - 1) == 'A' && S(i) == 'C') {
        count += 1
        count
      } else {
        count
      }
    }

    for (_ <- 0 until Q) {
      val l = sc.nextInt
      val r = sc.nextInt
      println(sums(r - 1) - sums(l - 1))
    }
  }
}