fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map{it.toInt()}
    val S = readLine()!!

    val b = Array(S.length + 1) { 0L }
    for (i in 1 until S.length) {
        if (S.substring(i - 1, i + 1) == "AC") {
            b[i + 1] = 1
        }
        b[i + 1] += b[i]
    }

    for (i in 1..Q) {
        val (l, r) = readLine()!!.split(" ").map{it.toInt()}
        println(b[r] - b[l])
    }
}
