fun main(args:Array<String>) {
  val (n, q) = readLine()!!.split(" ").map {it.toInt()}
  val s = readLine()!!
  val l = (1..q).map { readLine()!!.split(" ").map {it.toInt()}.toTypedArray()}.toTypedArray()
  solve(s, l)
}

fun solve(s:String, l:Array<Array<Int>>) {
  val r = create(s)

  for (ll in l) {
    println(r[ll[1] - 1] - r[ll[0] -1])
  }
}

fun create(s:String) : Array<Int> {
  var result = Array(s.length,  { 0 })
  var count = 0
  for (i in 1..s.length - 1) {
    if (s.substring(i - 1,  i + 1) == "AC") {
      ++count
    }
    result[i] =  count
  }
  return result
}
