fun main(args: Array<String>) {
    val (n, q) = readInputLine().split(" ").map { Integer.parseInt(it) }
    val s = readInputLine().toCharArray()
    
    // 予めカウントしておく
    val acCount = mutableListOf<Int>()
    acCount.add(0)
    var beforeA = false
    for (i in 1..n) {
        if (s[i - 1] == 'C' && beforeA) {
            acCount.add(acCount[i - 1] + 1)
        } else {
            acCount.add(acCount[i - 1])
        }
        if (s[i - 1] == 'A') {
            beforeA = true
        } else {
            beforeA = false
        }
    }
    
    for (i in 0 until q) {
        val (l, r) = readInputLine().split(" ").map { Integer.parseInt(it) }
        println("${acCount[r] - acCount[l]}")
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}
