import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val Q = sc.nextInt
    val S = sc.next
    val lr = Array.fill(Q)(sc.nextInt, sc.nextInt)

    lr.map { case (l, r) =>
      var s = S.substring(l - 1, r)
      var n = 0
      while (s.contains("AC")) {
        s = s.replaceFirst("AC", "")
        n += 1
      }
      n.toString
    }.mkString("\n")
  }
}
