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 l = new Array[Int](Q)
    val r = new Array[Int](Q)
    val sums = new Array[Int](N)
    for (i <- 0 until Q) {
      l(i) = sc.nextInt
      r(i) = sc.nextInt
    }
    var count = 0
    for (i <- 1 until N) {
      if (S(i - 1) == 'A' && S(i) == 'C') {
        count += 1
      }
      sums(i) = count
    }

    for (i <- 0 until Q) {
      println(sums(r(i) - 1) - sums(l(i) - 1))
    }

  }
}