import Foundation

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

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

for _ in 0..<Q {
    let input = readLine()!.split(" ")
    var tmpS = S.substringWithRange(S.startIndex.advancedBy(input[0]-1)...S.startIndex.advancedBy(input[1]-1))
    
    var ans = 0
    while let range = tmpS.rangeOfString("AC") {
        tmpS.removeRange(range)
        ans += 1
    }
    print(ans)
}