fun main(args : Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!!
    val queries = mutableListOf<Pair<Int, Int>>()
    (1..Q).forEach {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        queries.add(Pair(l, r))
    }

    val cumilativeArray = IntArray(N + 1)
    cumilativeArray[0] = 0
    var Aapperead = false
    S.forEachIndexed { index, c ->
        var ac = 0
        if (c == 'A') {
            Aapperead = true
        } else if (c == 'C' && Aapperead) {
            ac = 1
            Aapperead = false
        } else {
            Aapperead = false
        }
        cumilativeArray[index + 1] = cumilativeArray[index] + ac
    }

    queries.forEach { q ->
        val l = q.first
        val r = q.second
        println(cumilativeArray[r]  - cumilativeArray[l])
    }
}