fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map(String::toInt)
    val S = readLine()!!.toCharArray()
    val D = IntArray(N + 1)
    for (i in 2..N) {
        D[i] = D[i - 1]
        if (S[i - 2] == 'A' && S[i - 1] == 'C') D[i]++
    }
    repeat(Q) {
        val (l, r) = readLine()!!.split(" ").map(String::toInt)
        println(D[r] - D[l])
    }
}