import java.util.* 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val Q = sc.nextInt()
    val S = sc.next()
    val DP = IntArray(N+1){0}
    var isA = false
    for ((i,c) in S.withIndex()) {
        if (c == 'C' && isA) {
            isA = false
            DP[i+1] = DP[i]+1
        }
        else {
            if (c == 'A') isA = true
            else isA = false
            DP[i+1] = DP[i]
        }
    }
    //DP.forEach{println("$it ")}
    
    for (i in 0 until Q) {
        val l = sc.nextInt()
        val r = sc.nextInt()
    
        println(DP[r]-DP[l])
    }
}