fun main(args: Array<String>) = yorukatsu15c()

fun yorukatsu15c() {
    val (n, q) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!
    val lrList = (1..q).map {
        readLine()!!.split(' ').map { it.toInt() }.let { it[0] to it[1] }
    }

    val cSum = IntArray(n + 1)

    for (i in 1..s.lastIndex) {
        cSum[i] = if (s[i - 1] == 'A' && s[i] == 'C') 1 else 0
    }
    for (i in 0 until n) cSum[i + 1] += cSum[i]

    val answer = lrList.map {
        val (left, right) = it
        cSum[right - 1] - cSum[left - 1]
    }.joinToString(System.lineSeparator())

    println(answer)
}
