fun main(args: Array<String>) {
    val (n,q)=readLine()!!.split(" ").map { it.toInt() }
    val s=readLine()!!
    val lr = Array(q){readLine()!!.split(" ").map { s->s.toInt() }}
    var count =0
    val c = s.mapIndexed{i,c->
        if(c=='A'&&i<s.length-1&&s[i+1]=='C')count+=1
        count
    }
    lr.forEach {
        println(if(it[1]>1)c[it[1]-2]else{0} - if(it[0]>1)c[it[0]-2]else 0)
    }
}