n,q = gets.split.map(&:to_i)
s = gets.chomp

k = Array.new(n + 1,0)
(1..n - 1).each do |i|
    cnt = 0
    if s[i] == 'C' && s[i - 1] == 'A' 
        k[i + 1] = k[i] + 1 
    else
    k[i + 1] = k[i]
    end
end

q.times do
    l,r = gets.split.map(&:to_i)
    puts k[r] - k[l]
end
