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

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

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