fun main(args: Array<String>) = println(run {
    fun IntArray.accumulated(): List<Int> { var sum = 0; return this.map { sum += it; sum } }
    
    val (n,q) = readLine()!!.split(" ").map { it.toInt() }
    val s = "X" + readLine()!!
    val lr = (1..q).map { readLine()!!.split(" ").map { it.toInt() } }

    val ac = IntArray(s.length)
    Regex("AC").findAll(s).map { it.range.last }.forEach { ac[it] = 1 }
    val acs = ac.accumulated()

    lr.map { acs[it[1]]-acs[it[0]] }.joinToString("\n")
})

