import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.PrintWriter

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))
  val out = PrintWriter(PrintWriter(System.`out`))

  val (n, q) = br.readLine().split(" ").map { it.toInt() }
  val s = br.readLine().toCharArray()

  val table = IntArray(n)
  for(i in 0 until n-1) {
    table[i+1] =
      if(s[i] == 'A' && s[i+1] == 'C') table[i] + 1
      else table[i]
  }

  for(i in 1..q) {
    val (l, r) = br.readLine().split(" ").map { it.toInt() - 1 }
    out.println(table[r] - table[l])
  }

  out.flush()
}