import java.util.*

object MainKt {
	@JvmStatic
	fun main(args: Array<String>) {
		val scanner = Scanner(System.`in`)
		val n = scanner.nextInt()
		val q = scanner.nextInt()
		val s = scanner.next()

		val arr = IntArray(n) { i -> 0 }

		var befA = false
		for (i in 0..n-1){
			if (i!=0){
				if (befA && s.get(i)=='C') arr[i] = arr[i-1]+1
				else arr[i] = arr[i-1]
			}
			befA = s.get(i)=='A'
		}

		for (i in 0..q-1) {
			val l = scanner.nextInt()
			val r = scanner.nextInt()
			println(arr[r-1]-arr[l-1])
		}

	}
}