fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map(String::toInt)
    val S = readLine()!!
    val LR = Array(Q) { readLine()!!.split(" ").map(String::toInt).let { Pair(it[0], it[1]) } }

    val array = IntArray(S.length)
    for (i in 1 until S.length) {
        if (S.substring(i - 1, i + 1) == "AC") {
            array[i] = array[i - 1] + 1
        } else {
            array[i] = array[i - 1]
        }

    }
    LR.forEach {
        val (first, second) = it
        println(array[second - 1] - array[first - 1])
    }
}

