N,Q=gets.split.map(&:to_i)
S=gets.chomp
lrs=$<.read.split.map(&:to_i).each_slice(2)

ps = []
pos = 0
while pos = S.index('AC',pos)
    ps << pos
    pos += 1
end

lrs.each do |l,r|
    i = ps.bsearch_index {|p| l-1 <= p && p+1 <= r-1}
    unless i
        puts 0
        next
    end
    j = ps[i..-1].bsearch_index {|p| r-1 < p+1}
    puts (j||ps.length)-i
end

