import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val Q = sc.nextInt
    val S = sc.next
    val lr = Array.fill(Q)(sc.nextInt, sc.nextInt)

    val L = ArrayBuffer.fill(N + 2)(0)
    var n = 0
    for (i <- S.indices) {
      if (S(i) == 'A' && S(i + 1) == 'C') {
        n += 1
      }
      L(i + 1) = n
    }
    L(S.length + 1) = n

    val R = ArrayBuffer.fill(N + 2)(0)
    n = 0
    for (i <- S.indices.reverse if i > 0) {
      if (S(i - 1) == 'A' && S(i) == 'C') {
        n += 1
      }
      R(i + 1) = n
    }
    R(S.length + 1) = 0
    R(1) = R(2)
    R(0) = R(1)
    val all = n

//    println(L.map(_.toString).mkString(" "))
//    println(R.map(_.toString).mkString(" "))

    lr.map { case (l, r) =>
      (all - L(l - 1) - R(r + 1)).toString
    }.mkString("\n")
  }
}
