object Main extends App {
  @scala.annotation.tailrec
  def loop(chars: Seq[(Char, Int)], acc: Seq[Int]): Seq[Int] = chars match {
    case ('A', i) :: ('C', _) :: xs => loop(xs, acc :+ i)
    case _ :: Seq() => acc
    case _ :: xs => loop(xs, acc)
  }
  val sc = new java.util.Scanner(System.in)
  val n, q = sc.nextInt()
  val s = sc.next()
  val indecies = loop(s.zipWithIndex.toList, Seq.empty)
  List
    .fill(q)(sc.nextInt(), sc.nextInt())
    .map {
      case (start, end) =>
        indecies.count(i => start <= i + 1 && i + 2 <= end)
    }
    .foreach(println)
}
