n, q = gets.split(' ').map(&:to_i)
s = gets.rstrip
lrs = []
q.times{lrs << gets.split(' ').map(&:to_i)}

ms = [0]
1.upto(n) do | i |
  m = s.slice(0, i).scan(/AC/)
  ms << m.size
end
lrs.each do | lr |
  p ms[lr[1]] - ms[lr[0]]
end