object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in.tail.head
  val Q = in.tail.tail.map(_.split(' ').map(_.toInt))
  val A = (0 to S.size).toArray.map(_ => 0)
  (0 until S.size-1).foreach{ i =>
    if( S(i)=='A' && S(i+1)=='C' ) A(i+1) = A(i) + 1 else A(i+1) = A(i)
  }
  //println(A.toSeq)
  Q.foreach{ q =>
    val l = q(0)-1
    val r = q(1)-1
    val ret = A(r) - A(l)
    println(ret)
  }
}
