let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, Q) = (input[0], input[1])
let S = (readLine()!+"_").characters.map{String($0)}
var t = Array(count: N+1, repeatedValue: 0)
for i in 0..<N {
  	t[i+1] = t[i] + (S[i] + S[i+1] == "AC" ? 1 : 0)
}
for _ in 0..<Q {
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    let (l, r) = (input[0], input[1])
    print(t[r-1] - t[l-1])
}