fun main(args : Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val acs = IntArray(n){0}

    val regex = "AC".toRegex()
    regex.findAll(s).forEach { res ->
        acs[res.range.first+1] = 1
    }

    for (i in 1 until n) {
        acs[i] += acs[i-1]
    }

    repeat(q) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        println(acs[r-1]-acs[l-1])
    }
}