import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

let input = readLine()!.split(by: " ").map{Int($0)!}
let N = input[0]
let Q = input[1]
let S = readLine()!.characters.map{$0} + ["_"]

var sum = [0]
for i in 1...N {
    sum.append(sum[i-1])
    if (S[i-1] == "A") && (S[i] == "C") {
        sum[i] += 1
    }
}

for _ in 0..<Q {
    let input = readLine()!.split(by: " ").map{Int($0)!}
    print(sum[input[1]-1] - sum[input[0]-1])
}