fun main(args:Array<String>?): Unit {
    val (n, q) = readLine()!!.trim().split(' ').map(String::toInt)
    val s = readLine()!!.trim()
    val ac = Array(n){i ->
        if (i == 0) 0
        else if (s[i - 1] == 'A' && s[i] == 'C') 1
        else 0
    }
    for (i in 1 until s.length) ac[i] += ac[i - 1]
    
    repeat(q){
        val (l, r) = readLine()!!.trim().split(' ').map(String::toInt)
        println(
                ac[r - 1] - ac[l - 1]
        )
    }
}