(*,n) = gets.split.map(&:to_i)
s = gets.chomp
b = n.times.map{gets.split.map(&:to_i)}
index = []
i = s.index('AC')
while i != nil
 index << i
 i = s.index('AC', i+1)
end

puts b.map { |e| index.select{|s| e[0]-1 <= s && s <= e[1]-2 }.size }
