n, q = gets.split.map(&:to_i)
s = gets.chomp
l = Array.new(q)
r = Array.new(q)
q.times do |i|
  l, r = gets.split.map(&:to_i)
  ss = s[l-1..r-1]
  ans = 0
  for i in 0..ss.size-2 do
    if ss[i..i+1] == 'AC'
      ans += 1
    end
  end
  puts ans
end
