fun main(args: Array<String>) {
    val q = readLine()!!.split(' ')[1].toInt()
    var sum = 0
    var pre = ' '
    val totals = readLine()!!.map { c ->
        if (pre == 'A' && c == 'C') sum++
        pre = c
        sum
    }
    repeat(q) {
        val (l, r) = readLine()!!.split(' ').map { it.toInt() - 1 }
        println(totals[r] - totals[l])
    }
}
