import java.lang.StringBuilder

fun main(args:Array<String>) {
    val (n,q) = readLine()!!.split(" ").map { it.toInt() }
    val inpt = readLine()!!
    val ans = StringBuilder()
    val acCount = mutableListOf<Int>()
    acCount.add(0)
    for(i in (1 until inpt.length)) {
        acCount.add(acCount.last())
        if(inpt[i-1] == 'A' && inpt[i] == 'C') {
            acCount[i]++
        }
    }
    for(i in (1..q)) {
        var (start,end) = readLine()!!.split(" ").map { it.toInt() - 1 }
        if(start > 0 && inpt[start] == 'C') {
            start++
        }
        var cnt = acCount[end]
        if(start > 0) {
            cnt -= acCount[start - 1]
        }
        ans.appendln(cnt)
    }
    print(ans.toString())
}

