fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!!.toCharArray()
    val list = arrayListOf<Int>()
    var a = 0
    list.add(a)
    for (i in 0..(S.lastIndex - 1)) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            a = a.inc()
        }
        list.add(a)
    }

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