const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(' ').map{it.toInt()}
    val s = readLine()!!
    val ans = Array(n, {0})

    var cnt = 0
    var f = false
    for ((i, x) in s.withIndex()) {
        if (!f and (x == 'A')) {
            f = true
        } else if (!f) {
            f = false
        } else if (f and (x =='C')) {
            f = false
            cnt += 1
        } else if (f and (x == 'A')) {
            f = true
        } else {
            f = false
        }
        ans[i] = cnt
    }

    for (i in 0 until q) {
        val (l, r) = readLine()!!.split(' ').map{it.toInt()-1}
        println(ans[r] - ans[l])
    }
}
