import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val n = sc.nextInt
    val qn = sc.nextInt
    val s = sc.next
    val ql = List.fill(qn){(sc.nextInt, sc.nextInt)}

    val sl = buildSum(s)

    ql.foreach{q =>
      println(sl(q._2 - 1) - sl(q._1 - 1))
    }
  }

  def buildSum(str: String): Vector[Int] ={
    str.split("(?<=.)").foldLeft((Vector.empty[Int], false)){ case ((l,flgA), s) =>
      if (l.isEmpty) (Vector(0), s == "A")
      else
        s match{
          case x if "ATG".contains(x) => (l :+ l.last, s == "A")
          case "C" => if (flgA) (l :+ (l.last + 1), false) else (l :+ l.last, false)
        }
    }._1
  }
}