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

count = Array.new(n+1, 0)

for i in 0..n-1 do
  if (i != n) and (text[i] == 'A') and (text[i+1] == 'C') then
    count[i+1] = count[i]+1
  else
    count[i+1] = count[i]
  end
end
  
for i in 1..q do
  from, to = gets.chomp.split(' ').map{|s| s.to_i}
  print (count[to-1] - count[from-1])
  print "\n"
end
