type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [ for i in 1..n -> stream.ReadLine().ToCharArray() ]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let N, Q = util.Scan2 int
let S = util.Scan1 id
let qs = util.ScanMatrix Q int

let M = S
        |> Seq.pairwise
        |> Seq.scan (fun a -> fun cp -> a + (if cp = ('A','C') then 1 else 0)) 0
        |> Seq.toArray
qs
|> List.map (fun q ->
    sprintf "%d" (M.[q.[1]-1] - M.[q.[0]-1]))
|> String.concat "\n"
|> printfn "%s"
