object Main {
  def main(args: Array[String]): Unit = {
    val Array(str_length, check_str_nums) = io.StdIn.readLine.split(" ").map{_.toInt}
    val input_str = io.StdIn.readLine()
    var AC_head = Vector.empty[Int]

    (0 until input_str.length - 1).foreach{ i =>
      if(input_str(i) == 'A' && input_str(i + 1) == 'C') {
        AC_head = AC_head :+ i
      }
    }

    (0 until check_str_nums).foreach{ i =>
      var ac_count = 0
      val Array(start_str, end_str) = io.StdIn.readLine.split(" ").map{_.toInt}
      AC_head.foreach{ j =>
        if(start_str - 1 <= j && j + 1 <= end_str - 1) ac_count += 1
      }
      println(ac_count)
    }
  }
}