qs = gets.split(' ').map(&:to_i)
x = []
s = gets.to_s.chomp.split("")
qs[1].times { |q| x << gets.split(' ').map(&:to_i) }
num = []
count = 0
s.each_with_index do |string, i|
    if i == 0
        num << 0
        next
    end
    if s[i-1] == 'A' and s[i] == 'C'
        count += 1
    end
    num << count
end
x.each do |q|
    ans = num[q[1]-1] - num[q[0]-1]
    puts ans
end
