import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input = readLine()!.split(" ")
let N = input[0]
let Q = input[1]
let S = readLine()!

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

for _ in 0..<Q {
    let input = readLine()!.split(" ")
    let l = input[0]
    let r = input[1]
    let ans = sum[r-1] - sum[l-1]
    print(ans)
}