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+1
    pos += 1
end

lrs.each do |l,r|
    i = ps.index {|p| l <= p && p+1 <= r}
    unless i
        puts 0
        next
    end
    j = ps.rindex {|p| l <= p && p+1 <= r}
    puts j-i+1
end

