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

    val tArray = Array(n){0}
    for(i in 0 until n - 1){
        tArray[i+1] = tArray[i] + if(s.substring(i, i + 2) == "AC") 1 else 0
    }

    for(q in qlist){
        val (l, r) = q
        val ans = tArray[r-1] - tArray[l-1]
        println(ans)
    }
}