import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val N, Q = sc.nextInt()
    val S = sc.next()
    val question = 0.until(Q).map{_ =>
      val l, r = sc.nextInt()
      (l, r)
    }

    @tailrec
    def ACNum(str: String, num: Int = 0): Int = {
      val d = str.diff("AC")
      if (d.isEmpty || d == str) num
      else ACNum(d, num + 1)
    }
    val result = question.map {
      case (l, r) =>
        val sub = S.substring(l - 1, r)
        ACNum(sub)
    }.toList

    result.foreach(i => println(i))
  }
}
