def check(str)
  count = 0
  str.each_cons(2).with_index do |arr,i|
    if arr.join == "AC"
      count += 1
    end
  end
  count
end

n,q = gets.chomp.split(' ').map(&:to_i)
s = gets.chomp.split('')

sum = []
str = []
s.size.times do |i|
  str << s[i]
  sum << check(str)
end

q.times do
  l,r = gets.chomp.split(' ').map(&:to_i)
  puts sum[r-1] - sum[l-1]
end
