n,q = gets.split.map(&:to_i)
s = gets.chomp.chars
l = []
r = []
q.times do |i|
    l[i],r[i] = gets.split.map(&:to_i)
end
for i in 0..(q-1)
    cnt = 0
    for j in (l[i]-1)..(r[i]-2)
        if s[j] == 'A' && s[j+1] == 'C'
            cnt += 1
        end
    end
    puts cnt
end