object Main {
  val sc = new java.util.Scanner(System.in)

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val Q = sc.nextInt
    val S = sc.next
    val list = Array.fill(Q, 2)(sc.nextInt)

    var dp = Array.fill(S.length)(0)

    for{
      end <- 1 until S.length
    } yield {
      dp(end) =
        if(S.charAt(end-1) == 'A' && S.charAt(end) == 'C'){
         dp(end-1) + 1
      } else {
        dp(end-1)
      }
    }

    list.foreach{ case Array(l, r) =>
        println(dp(r-1) - dp(l-1))
    }
  }
}