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