def count_ac(s)
  n = 0
  i = 0
  while true
    r = s.index('AC', i)
    if r
      n += 1
      i = (r + 2)
    else
      break
    end
  end

  return n
end

n, q = gets.chomp.split(' ').map {|v| v.to_i}
s = gets.chomp

q.times do |i|
  l, r = gets.chomp.split(' ').map {|v| v.to_i}
  s1 = s.slice(l - 1, r - l + 1)
  num = count_ac(s1)
  puts num
end
