object Main extends App {
	val Array(n, q) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val s = scala.io.StdIn.readLine.toList.toArray

	val a = new Array[Int](s.size + 1)
	val b = new Array[Int](q)

	for(i<-0 until s.size - 1){
		if(s(i) == 'A' && s(i+1) == 'C'){
			a(i+1) = 1
		}
	}

	for(i<-0 until q){
		val Array(l, r) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

		b(i) = a.take(r).sum - a.take(l).sum
	}

	for(i<-0 until q){
		println(b(i))
	}

}
