object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, Q = sc.nextInt()
    sc.nextLine()
    val S = sc.nextLine()
    val leftAc = new Array[Int](N+1) // 左からi文字目までのACの数
    def leftAcCount(i: Int, acm: Int): Unit =
      if (i < N)
        if (S(i-1) == 'A' && S(i) == 'C') {
          leftAc(i) = acm + 1
          leftAcCount(i + 1, acm + 1)
        } else {
          leftAc(i) = acm
          leftAcCount(i + 1, acm)
        }
      else {}
    leftAc(0) = 0
    leftAcCount(1, 0)

    val results = (0 until Q) map { _ =>
      val l, r = sc.nextInt()
      leftAc(r-1) - leftAc(l-1)
    }
    println(results.mkString("\n"))
  }

}