N, Q = gets.split.map(&:to_i)
S = gets.chomp

i = 0
cache = [0] * N
while true
  i = S.index('AC', i)
  break if i.nil?
  cache[i] = 1
  i += 2
end

Q.times do
  l, r = gets.split.map(&:to_i)
  t = cache[(l-1)..(r-1)]
  ans = t.inject(&:+)
  puts t.last == 0 ? ans : ans - 1
end