import scala.io.StdIn

object Main {

  case class Query(l: Int, r: Int)
  case class Memo(cnt: Int, pre: Char)

  def main(args: Array[String]): Unit = {

    val Array(n, q) = StdIn.readLine().split(' ').map(_.toInt)
    val s = StdIn.readLine().toIndexedSeq
    val lrs = (1 to q).map{_ =>
      val Array(l, r) = StdIn.readLine().split(' ').map(_.toInt)
      Query(l, r)
    }.toList
    val memos = s.foldLeft(Vector(Memo(0, 'Z'))){(acc, c) =>
      val memo = acc.last
      if (memo.pre == 'A' && c == 'C') {
        acc :+ Memo(memo.cnt + 1, c)
      } else {
        acc :+ Memo(memo.cnt, c)
      }
    }
    val ans = lrs.map{q =>
      memos(q.r).cnt - memos(q.l).cnt
    }
    ans.map(println)
  }

}
