import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val q = sc.nextInt()
  val s = sc.next()
  val lr = (1..q).map { Pair(sc.nextInt(), sc.nextInt()) }

  
  val t = Array(n) { 0 }
  for (i in 0 until n-1) {
    val s1 = s[i]
    val s2 = s[i+1]
    t[i + 1] = t[i] + if (s1 == 'A' && s2 == 'C') { 1 } else { 0 }
  }

  val list = mutableListOf<Int>()
  for (lri in lr) {
    val l = lri.first
    val r = lri.second
    val ti = t[r-1] - t[l-1]
    list.add(ti)
  }

  println(list.joinToString("\n"))

}
