private fun readInts(): List<Int> = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (N, Q) = readInts()
    val S = readLine()!!
    val lr = (0 until Q).map { readInts().map { index -> index - 1 } } // 0-started

    val sum = Array(N) { 0 }
    for (index in 1 until N) {
        val x = if (S[index - 1] == 'A' && S[index] == 'C') 1 else 0

        sum[index] = sum[index - 1] + x
    }

    lr
        .map { line ->
            val (l, r) = line
            sum[r] - sum[l]
        }.forEach { println(it) }
}