fun main(args: Array<String>) {
    abc122c()
}

fun abc122c() {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.toCharArray()
    val lrList = (1..q).map { readLine()!!.split(" ") }
        .map { Pair(it[0].toInt() - 1, it[1].toInt() - 1) }

    // 左にAがあるCをXに置き換える : ACACG -> AXAXG
    val acReplaced = (s.indices).map {
        if (it == 0) {
            s[0]
        } else {
            val cPrev = s[it - 1]
            val c = s[it]
            if (cPrev == 'A' && c == 'C') 'X' else c
        }
    }

    // 累積和とっておく
    val cumulativeSum = mutableListOf(0)
    var sumTemp = 0
    for (i in 1 until acReplaced.size) {
        if (acReplaced[i] == 'X') {
            sumTemp++
        }
        cumulativeSum.add(sumTemp)
    }

    val answer = lrList.map {
        cumulativeSum[it.second] - cumulativeSum[it.first]
    }

    println(answer.joinToString(separator = System.lineSeparator()))
}
