n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("")
s = s.unshift(" ")
arr = Array.new(n+1,0)
i = 2
ans = 0
while true
    s[i] == "C" && s[i-1] == "A" ? arr[i] = ans + 1 : arr[i] = ans
    break if i == n
    ans = arr[i]
    i += 1
end
q.times do
    l, r = gets.chomp.split(" ").map(&:to_i)
    all = arr[r] - arr[l]
    puts all
end